Method Stdio.File()->connect()
- Method
connect
variantintconnect(string(7bit)host,int(0..)|string(7bit)port)
variantintconnect(string(7bit)host,int(0..)|string(7bit)port,string(7bit)client,int(0..)|string(7bit)client_port)
variantstringconnect(string(7bit)host,int(0..)|string(7bit)port,string(8bit)data)
variantstring|zeroconnect(string(7bit)host,int(0..)|string(7bit)port,int(0)|string(7bit)client,int(0..)|string(7bit)client_port,string(8bit)data)- Description
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
hostargument is the hostname or IP number of the remote machine.A local IP and port can be explicitly bound by specifying
clientandclient_port.If the
dataargument 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)
- Returns
This function returns
1or the remainingdatafor success,0otherwise.- Note
To use nonblocking mode, open_socket() and set_nonblocking() (or equivalent) need to be called before this function.
- Note
In nonblocking mode
0(zero) may be returned and errno() set toEWOULDBLOCKorWSAEWOULDBLOCK.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(), open_socket(),::connect()