Method Stdio.File()->connect()
- Method
connect
variant
int
connect(string(7bit)
host
,int(0..)
|string(7bit)
port
)
variant
int
connect(string(7bit)
host
,int(0..)
|string(7bit)
port
,string(7bit)
client
,int(0..)
|string(7bit)
client_port
)
variant
string
connect(string(7bit)
host
,int(0..)
|string(7bit)
port
,string(8bit)
data
)
variant
string
|zero
connect(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
host
argument is the hostname or IP number of the remote machine.A local IP and port can be explicitly bound by specifying
client
andclient_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)
- Returns
This function returns
1
or the remainingdata
for success,0
otherwise.- 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 toEWOULDBLOCK
orWSAEWOULDBLOCK
.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()