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'),
});
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 });