Method Stdio.File()->async_connect()
- Method async_connect
int
async_connect(string
host
,int
|string
port
,function
(int
,mixed
... :void
)callback
,mixed
...args
)- Description
Open a TCP/IP connection asynchronously.
This function is similar to connect(), but works asynchronously.
- Parameter
host
Hostname or IP to connect to.
- Parameter
port
Port number or service name to connect to.
- Parameter
callback
Function to be called on completion. The first argument will be
1
if a connection was successfully established, and0
(zero) on failure. The rest of the arguments tocallback
are passed verbatim fromargs
.- Parameter
args
Extra arguments to pass to
callback
.- Returns
Returns
0
on failure, and1
ifcallback
will be used.- Note
The socket may be opened with open_socket() ahead of the call to this function, but it is not required.
- Note
This object is put in callback mode by this function. For
callback
to be called, the backend must be active. See e.g. set_read_callback for more details about backends and callback mode.- Note
The socket will be in nonblocking state if the connection is successful, and any callbacks will be cleared.
- See also