Next: create

Prev: conn_assign

connect

connect(address, port, receiver)
This function establishes a connection to the remote Internet host named by address (a string giving the IP address of the remote host) at the port port.

If address is not a valid IP address, then connect() throw an ~address error. If a socket cannot be created for the connection, then connect() throws a ~socket error. Otherwise, connect() attemptes to connect to the remote host and returns 1 immediately; it does not wait to see if the connection attempt succeeded.

If the connection succeeds, then the server will send the object receiver a connect message, with one argument the task ID of the task which called connect() (see task_id). receiver then becomes the handler object for the connection, and receives parse messages when lines arrive from the connection, as well as a disconnect message when the connection terminates.

If the connection fails, then the object receiver will receive a failed message with two arguments, the task ID of the task which called connect(), and an error code: ~refused indicates that the connection was refused, ~net indicates that the network of the remote host could not be reached, ~timeout indicates that the connection attempt timed out, and ~other indicates that some other error occurred.