Method Stdio.File()->connect()

Method connect

variant int connect(string host, int(0..)|string port)
variant int connect(string host, int(0..)|string port, string client, int(0..)|string client_port)
variant string connect(string host, int(0..)|string port, string data)
variant string|zero connect(string host, int(0..)|string port, int(0)|string client, int(0..)|string client_port, string data)


Open a TCP/IP connection to the specified destination.

In nonblocking mode, success is indicated with the write-callback, and failure with the close-callback or the read_oob-callback.

The host argument is the hostname or IP number of the remote machine.

A local IP and port can be explicitly bound by specifying client and client_port.

If the data argument is included the socket will use TCP_FAST_OPEN if posible. In this mode the the function will return the part of the data that has not been sent to the remote server yet instead of 1 (you will have to use write to send this data).

Note that TCP_FAST_OPEN requires server support, the connection might fail even though the remote server exists. It might be advisable to retry without TCP_FAST_OPEN (and remember this fact)


This function returns 1 or the remaining data for success, 0 otherwise.


In nonblocking mode 0 (zero) may be returned and errno() set to EWOULDBLOCK or WSAEWOULDBLOCK.

This should not be regarded as a connection failure. In nonblocking mode you need to wait for a write or close callback before you know if the connection failed or not.

See also

query_address(), async_connect(), connect_unix()