server.listen([port[, host[, backlog]]][, callback])
port<number>host<string>backlog<number>server.listen()函数的常用参数。callback<Function>.- 返回:<net.Server>
启动一个 TCP 服务器,在指定的 port 和 host 上监听连接。
🌐 Start a TCP server listening for connections on the given port and host.
如果省略 port 或者设置为 0,操作系统将分配一个任意未使用的端口,可以在 'listening' 事件触发后通过 server.address().port 获取该端口。
🌐 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.
如果省略 host,当 IPv6 可用时,服务器将接受来自 未指定的 IPv6 地址 (::) 的连接,否则将接受来自 未指定的 IPv4 地址 (0.0.0.0) 的连接。
🌐 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.
在大多数操作系统中,监听 未指定的 IPv6 地址 (::) 可能会导致 net.Server 也监听 未指定的 IPv4 地址 (0.0.0.0)。
🌐 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).