Question

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?

Was it helpful?

Solution 2

No, you have to do that at the application level if you need to do that. The internet doesn't guarantee that two different packets will take the same route, so timing can vary. Maybe add a timestamp to each message so you can sort by that timestamp to keep things in order.

OTHER TIPS

Since previous answers could potentially be misleading, I think it's important to clarify one thing:

When using Socket.io with WebSockets, packet order is guaranteed to be maintained.

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:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top