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


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

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

如果host省略,如果IPv6可用,服务器将会接收基于unspecified IPv6 address (::)的连接,否则接收基于unspecified IPv4 address (0.0.0.0)的连接

注意: 在大多数的系统, 监听unspecified IPv6 address (::)可能导致net.Server也监听unspecified IPv4 address (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).