server.listen([port[, host[, backlog]]][, callback])
-
port
<number> -
host
<string> -
backlog
<number>server.listen()
函数的通用参数。¥
backlog
<number> Common parameter ofserver.listen()
functions. -
callback
<Function> . -
返回:<net.Server>
¥Returns: <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
).