jsonwebrtcrtcdatachannel

Are WebRTC data channel packets atomic?


I want to use a WebRTC data channel to exchange json messages between peers.

Can I safely assume that each json message arrives atomically remotely (not like in TCP where packets may be split or chunked together) or do I need implement something like a length prefix to know where one message ends and another begin?

Using a reliable channel and possibly a tcp turn server, if that's relevant.


Solution

  • Yes, according to the webRTC draft spec, whatever message you send() down a data channel should arrive in a single onmessage callback at the far end.

    In real life however, Chrome sometimes calls onmessage with a partial message when it runs out of buffers. If you keep your messages <64k this seems not to happen.