dtls.connect(host, port, options?): DTLSSession
Attributes
host:
stringRemote host to connect to.
port:
numberRemote port to connect to.
options:
ObjectrejectUnauthorized?:
booleanWhen
true, the server's certificate must
both chain to a trusted CA and match the expected identity (servername,
or host when servername is not set); otherwise the handshake is
aborted and session.opened rejects. When false, the certificate is not
verified. Default: true.servername?:
stringServer name used for the SNI (Server Name
Indication) extension and as the identity checked during certificate
verification. Default: the
host argument. Set to '' to disable SNI.
SNI is never sent for IP address literals.bindHost?:
stringLocal bind address. Default:
'0.0.0.0'.bindPort?:
numberLocal bind port. Default:
0 (ephemeral).srtp:
stringSRTP protection profile names.
mtu?:
numberMaximum transmission unit. Default:
1200.Returns:
DTLSSessionConnects to a DTLS server. Returns a DTLSSession whose opened property
is a Promise that resolves when the handshake completes.
import { connect } from 'node:dtls'; import { readFileSync } from 'node:fs'; const session = connect('localhost', 4433, { ca: [readFileSync('ca-cert.pem')], }); await session.opened; session.send('hello'); session.onmessage = (data) => { console.log('Received:', data.toString()); };