socket.connect()
在给定套接字上启动连接。
【Initiate a connection on a given socket.】
可能的语法有:
【Possible signatures:】
socket.connect(options[, connectListener])socket.connect(path[, connectListener])用于 IPC 连接。socket.connect(端口[, 主机]][, connectListener])用于 TCP 连接。- 返回:<net.Socket> 套接字本身。
此函数是异步的。当连接建立时,将触发 'connect' 事件。如果连接时出现问题,不会触发 'connect' 事件,而会触发 'error' 事件,并将错误传递给 'error' 监听器。最后一个参数 connectListener,如果提供,将作为 'connect' 事件的监听器被添加,只触发一次。
【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.】
此函数应仅在触发 'close' 事件后用于重新连接套接字,否则可能导致未定义的行为。
【This function should only be used for reconnecting a socket after
'close' has been emitted or otherwise it may lead to undefined
behavior.】