dtls.listen(callback, options): DTLSEndpoint
Attributes
callback:
FunctionCalled for each new DTLS session accepted by the
server.
session:
DTLSSessionThe new session.
options:
Objectport:
numberPort to bind to. Required.
host?:
stringAddress to bind to. Default:
'0.0.0.0'.ciphers:
stringOpenSSL cipher list string.
srtp:
stringColon-separated SRTP protection profile names
(e.g.,
'SRTP_AES128_CM_SHA1_80:SRTP_AEAD_AES_128_GCM').requestCert?:
booleanRequest client certificate. Default:
false.mtu?:
numberMaximum transmission unit for DTLS records.
Default:
1200.Returns:
DTLSEndpointCreates a DTLS server bound to the specified address and port. The server uses automatic HMAC-based cookie exchange for DoS protection.
import { listen } from 'node:dtls'; import { readFileSync } from 'node:fs'; const endpoint = listen((session) => { session.onmessage = (data) => { console.log('Received:', data.toString()); session.send('pong'); }; session.onhandshake = (protocol) => { console.log('Handshake complete:', protocol); }; }, { cert: readFileSync('server-cert.pem'), key: readFileSync('server-key.pem'), port: 4433, }); console.log('DTLS server listening on', endpoint.address);