new net.Socket([options])


  • options <Object> 可用的选项有:
    • fd <number> 如果指定,则使用给定的文件描述符封装现有的套接字,否则将创建新的套接字。
    • allowHalfOpen <boolean> 如果设置为 false,则当可读端结束时,套接字将自动结束可写端。 有关详细信息,请参阅 net.createServer()'end' 事件。 默认值: false
    • readable <boolean> 当传入 fd 时,则允许在套接字上读取,否则将被忽略。 默认值: false
    • writable <boolean> 当传入 fd 时,则允许在套接字上写入,否则将被忽略。 默认值: false
  • 返回: <net.Socket>

创建新的套接字对象。

新创建的套接字可以是 TCP 套接字或流式 IPC 端点,这取决于它 connect() 什么。

  • options <Object> Available options are:
    • fd <number> If specified, wrap around an existing socket with the given file descriptor, otherwise a new socket will be created.
    • allowHalfOpen <boolean> If set to false, then the socket will automatically end the writable side when the readable side ends. See net.createServer() and the 'end' event for details. Default: false.
    • readable <boolean> Allow reads on the socket when an fd is passed, otherwise ignored. Default: false.
    • writable <boolean> Allow writes on the socket when an fd is passed, otherwise ignored. Default: false.
  • Returns: <net.Socket>

Creates a new socket object.

The newly created socket can be either a TCP socket or a streaming IPC endpoint, depending on what it connect() to.