socket.connect()
在给定的套接字上发起连接。
可能的语法有:
socket.connect(options[, connectListener])socket.connect(path[, connectListener])用于 IPC 连接。socket.connect(port[, host][, connectListener])用于 TCP 连接。- 返回: <net.Socket> 套接字自身
此函数是异步的。
建立连接后,将触发 'connect' 事件。
如果连接出现问题,则将触发 'error' 事件并将错误传给 'error' 监听器,而不是触发 'connect' 事件。
最后一个参数 connectListener(如果提供)将作为 'connect' 事件的监听器添加一次。
此函数仅用于在触发 'close' 之后重新连接套接字,否则可能导致未定义的行为。
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.