socket.connect()
在给定套接字上启动连接。
¥Initiate a connection on a given socket.
可能的语法有:
¥Possible signatures:
-
socket.connect(path[, connectListener])用于 IPC 连接。¥
socket.connect(path[, connectListener])for IPC connections. -
socket.connect(port[, host][, connectListener])用于 TCP 连接。¥
socket.connect(port[, host][, connectListener])for TCP connections. -
返回:<net.Socket> 套接字自身
¥Returns: <net.Socket> The socket itself.
这个函数是异步的。建立连接后,将触发 '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.