socket.connect(options[, connectListener])

在给定的 socket 上初始化一个连接。通常该方法是不需要的,应该使用 net.createConnection() 来创建和打开 socket。一般只在实现一个自定义的 Socket 的时候使用该方法。

对于 TCP 连接可能的 options 有:

对于 IPC 连接可能的 options 有:

返回 socket.

Initiate a connection on a given socket. Normally this method is not needed, the socket should be created and opened with net.createConnection(). Use this only when implementing a custom Socket.

For TCP connections, available options are:

  • port <number> Required. Port the socket should connect to.
  • host <string> Host the socket should connect to. Default: 'localhost'.
  • localAddress <string> Local address the socket should connect from.
  • localPort <number> Local port the socket should connect from.
  • family <number>: Version of IP stack, can be either 4 or 6. Default: 4.
  • hints <number> Optional dns.lookup() hints.
  • lookup <Function> Custom lookup function. Default: dns.lookup().

For IPC connections, available options are: