Is there some kind of ordering mechanism in Socket.IO that guarantees that events are received in order by clients?
For example: if a server emits event Evt1
to client A, and the server broadcasts Evt2
to all clients.
Thus client A receives Evt1
then Evt2
and only in that order.
My guess is NO and, if it's the case, how would you implement it, or are there existing solutions?
When using Socket.io with WebSockets, packet order is guaranteed to be maintained.
Socket.IO allows bi-directional communication between client and server. Bi-directional communications are enabled when a client has Socket.IO in the browser, and a server has also integrated the Socket.IO package. While data can be sent in a number of forms, JSON is the simplest.
socket-io. client is the code for the client-side implementation of socket.io. That code may be used either by a browser client or by a server process that is initiating a socket.io connection to some other server (thus playing the client-side role in a socket.io connection).
JS, Socket.IO enables asynchronous, two-way communication between the server and the client. This means that the server can send messages to the client without the client having to ask first, as is the case with AJAX.
Since previous answers could potentially be misleading, I think it's important to clarify one thing:
This is an old post, but it's worth noting that Socket.io over WebSockets actually does guarantee event ordering is maintained. This is because TCP itself, which is the underlying technology for WebSockets & HTTP guarantees packet ordering to be maintained. However Socket.io also supports several other protocols that do not guarantee order.
There have been several posted questions about this issue, supporting this fact:
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