Ad

Websockets Message Integrity

When using a WebSocket full-duplex data connection between a client and a server, am I guaranteed, when sending two messages from the server, that I will receive those two exact same messages on the client, something TCP does not ?

In other words, if the server sends in turn hello and then its me, does the client always receive two messages containing hello and its me or is it possible the client receives helloit and then s me or even one only message like helloits me ?

Ad

Answer

WebSocket originally had text message start and finish bytes, but that's old information. There's a length component in the (Dec 2011) framing. And btw, there a flag in the framing spec that specifies whether the frame is the whole "message" or a "message fragment", ie, there are other frames that make up this "message". Its up to the receiver to combine the fragments correctly to pass up to the application code. Normally you don't have to think about this unless you have very large "messages" (think of WS "messages" as "data" rather than true messages... WS is not really a "messaging" protocol per se).

But note, WebSocket is a low-level transport. Think of it like a web-based TCP. Application programmers should use high-level protocols "over WS/WSS" and not worry about ordering, reconnection, presence, pub/sub, tuple-spaces, guaranteed delivery, etc, etc. If we don't do this, dozens and dozens of decades-old application protocols will be re-invented.

Ad
source: stackoverflow.com
Ad