server.listen([port[, host[, backlog]]][, callback])


启动一个 TCP 服务监听输入的 porthost

如果 port 省略或是 0,系统会随意分配一个在 'listening' 事件触发后能被 server.address().port 检索的无用端口。

如果 host 省略,如果 IPv6 可用,服务器将会接收基于未指定的 IPv6 地址 (::) 的连接,否则接收基于未指定的 IPv4 地址 (0.0.0.0) 的连接。

在大多数的系统, 监听未指定的 IPv6 地址 (::) 可能导致 net.Server 也监听未指定的 IPv4 地址 (0.0.0.0)。

Start a TCP server listening for connections on the given port and host.

If port is omitted or is 0, the operating system will assign an arbitrary unused port, which can be retrieved by using server.address().port after the 'listening' event has been emitted.

If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise.

In most operating systems, listening to the unspecified IPv6 address (::) may cause the net.Server to also listen on the unspecified IPv4 address (0.0.0.0).