What is the difference between WebRTC and WebSockets for low level data communication

There is one significant difference: WebSockets works via TCP, WebRTC works via UDP.
In fact, WebRTC is SRTP protocol with some additional features like STUN, ICE, DTLS etc. and internal VoIP features such as Adaptive Jitter Buffer, AEC, AGC etc.

So, WebSockets is designed for reliable communication. It is a good choice if you want to send any data that must be sent reliably.

When you use WebRTC, the transmitted stream is unreliable. Some packets can get lost in the network. It is bad if you send critical data, for example for financial processing, the same issue is ideally suitable when you send audio or video stream where some frames can be lost without any noticeable quality issues.

If you want to send data channel via WebRTC, you should have some forward error correction algorithm to restore data if a data frame was lost in the network.

Leave a Comment