quic.connect(address[, options])


启动新的客户端会话。

¥Initiate a new client-side session.

import { connect } from 'node:quic';
import { Buffer } from 'node:buffer';

const enc = new TextEncoder();
const alpn = 'foo';
const client = await connect('123.123.123.123:8888', { alpn });
await client.createUnidirectionalStream({
  body: enc.encode('hello world'),
}); 

默认情况下,每次调用 connect(...) 都会创建一个绑定到新的随机本地 IP 端口的新本地 QuicEndpoint 实例。要指定要使用的确切本地地址,或通过单个本地端口多路复用多个 QUIC 会话,请传递 endpoint 选项,并使用 QuicEndpointEndpointOptions 作为参数。

¥By default, every call to connect(...) 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.

import { QuicEndpoint, connect } from 'node:quic';

const endpoint = new QuicEndpoint({
  address: '127.0.0.1:1234',
});

const client = await connect('123.123.123.123:8888', { endpoint });