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(...) 都会创建一个新的本地 QuicEndpoint 实例,并绑定到一个随机的本地 IP 端口。要指定使用的确切本地地址,或者在单个本地端口上复用多个 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 });