quic.listen(onsession,[options])
-
onsession
quic.OnSessionCallback -
options
quic.SessionOptions -
返回:<Promise> 对 quic.QuicEndpoint 的 promise
¥Returns: <Promise> a promise for a quic.QuicEndpoint
配置端点以作为服务器进行监听。当远程对等方发起新会话时,将使用创建的会话调用给定的 onsession
回调。
¥Configures the endpoint to listen as a server. When a new session is initiated by
a remote peer, the given onsession
callback will be invoked with the created
session.
import { listen } from 'node:quic';
const endpoint = await listen((session) => {
// ... handle the session
});
// Closing the endpoint allows any sessions open when close is called
// to complete naturally while preventing new sessions from being
// initiated. Once all existing sessions have finished, the endpoint
// will be destroyed. The call returns a promise that is resolved once
// the endpoint is destroyed.
await endpoint.close();
默认情况下,每次调用 listen(...)
都会创建一个绑定到新的随机本地 IP 端口的新本地 QuicEndpoint
实例。要指定要使用的确切本地地址,或通过单个本地端口多路复用多个 QUIC 会话,请传递 endpoint
选项,并使用 QuicEndpoint
或 EndpointOptions
作为参数。
¥By default, every call to listen(...)
will create a new local
QuicEndpoint
instance bound to a new random local IP port. To
specify the exact local address to use, or to multiplex multiple
QUIC sessions over a single local port, pass the endpoint
option
with either a QuicEndpoint
or EndpointOptions
as the argument.
最多,任何单个 QuicEndpoint
只能配置为作为服务器监听一次。
¥At most, any single QuicEndpoint
can only be configured to listen as
a server once.