After creating an RTCPeerConnection, call createDataChannel('label', options) on the offering peer before generating an offer; options can include ordered: false for unordered delivery and maxRetransmits: 0 for fully unreliable (useful for game state), or leave defaults for reliable ordered delivery.
The answering peer listens for the RTCPeerConnection 'datachannel' event to receive the remote channel; do not call createDataChannel on the answering side for the same label.
Wait for the channel's 'open' event before sending data; sending before the channel opens silently discards messages in some implementations.
Send binary data (ArrayBuffer or Blob) for efficiency; strings are valid but incur UTF-8 encoding overhead. Keep individual messages below the SCTP PMTU to avoid fragmentation — a common safe size is under 16 KB.
For large transfers, implement your own chunking: break the payload into chunks, send them sequentially, and reassemble on the receiver using a sequence number you include in each chunk.
To negotiate a data channel out-of-band (avoiding the SDP renegotiation for the channel itself), set negotiated: true and id: <same integer on both sides> in the options on both peers before connecting.
Known gotchas
Unreliable unordered data channels (maxRetransmits: 0, ordered: false) can still exhibit latency spikes due to SCTP's congestion control — they are not equivalent to raw UDP; benchmark under realistic network conditions.
The SCTP association that carries data channels shares the same ICE/DTLS path as media; a network blip that restarts ICE also closes and reopens all data channels.
Sending large volumes of data without backpressure can fill the SCTP send buffer and cause bufferedAmount to grow unboundedly; monitor channel.bufferedAmount and pause sending when it exceeds channel.bufferedAmountLowThreshold.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp