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
?
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.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM