chickadee » tcp6 » tcp-connect

tcp-connect HOSTNAME #!optional TCPPORTprocedure

Establishes a client-side TCP connection to the machine with the node name or IP address HOSTNAME (a string) at TCPPORT (an exact integer or a service name) and returns two values: an input- and output-port for communicating with the remote process.

If the TCPPORT is omitted, the port is parsed from the HOSTNAME string. The format expected is "HOST:PORT", or "[HOST]:PORT" if HOST is an IPv6 string. The PORT can either be a string representation of an integer or a service name which is translated to an integer using address-information from socket.

Address resolution is performed using address-information, which may return multiple addresses for a given hostname, including both IPv6 and IPv4 addresses. tcp-connect will try each of these in turn until one succeeds. See tcp-connect/ai for more information. For example, connecting to "localhost:ssh" may connect to "[::1]:22", "[fe80::1%lo0]:22", and "127.0.0.1:22" in turn, until an ssh listener is contacted.

The current value of tcp-connect-timeout is used to determine the maximum number of milliseconds (if any) to wait until the connection is established. When the connection takes place any read- and write-operations on the returned ports will use the current values (at the time of the call to tcp-connect) of tcp-read-timeout and tcp-write-timeout, respectively, to determine the maximum number of milliseconds to wait for input/output before a timeout error is signalled.

Note: any I/O on the ports returned will not block other running threads.