socket.connect()
在给定的套接字上启动一个连接。
可能的签名:
socket.connect(options[, connectListener])
socket.connect(path[, connectListener])
用于 IPC 连接。socket.connect(port[, host][, connectListener])
用于 TCP 连接。- 返回: <net.Socket> socket 自身。
该方法是异步的。当连接建立了的时候,'connect'
事件将会被触发。如果连接过程中有问题,'error'
事件将会代替 'connect'
事件被触发,并将错误信息传递给 'error'
监听器。
最后一个参数 connectListener
,如果指定了,将会被添加为 'connect'
事件的监听器。
This function should only be used for reconnecting a socket after
'close'
has been emitted or otherwise it may lead to undefined
behavior.
Initiate a connection on a given socket.
Possible signatures:
socket.connect(options[, connectListener])
socket.connect(path[, connectListener])
for IPC connections.socket.connect(port[, host][, connectListener])
for TCP connections.- Returns: <net.Socket> The socket itself.
This function is asynchronous. When the connection is established, the
'connect'
event will be emitted. If there is a problem connecting,
instead of a 'connect'
event, an 'error'
event will be emitted with
the error passed to the 'error'
listener.
The last parameter connectListener
, if supplied, will be added as a listener
for the 'connect'
event once.
This function should only be used for reconnecting a socket after
'close'
has been emitted or otherwise it may lead to undefined
behavior.