0

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.

monoceres
  • 4,722
  • 4
  • 38
  • 63
  • Yes, this is why we have APIs. Just because things are split up in lower level code doesn't mean the API has to do the same. – jib Nov 18 '16 at 17:15

1 Answers1

1

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.

Tim Panton
  • 469
  • 3
  • 4