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
?
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.
Having a very bad connection you may lose a message (however it should be resend with tcp), but it's very unlikely to be splitted in such a way. Each text message has boundaries - start (0x00) and finish (0xFF) bytes. Browser should not mess messages. Likely you can get messages in another order.
How can you be more sure:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With