Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Socket.io garantee that broadcasted events are received in order client side?

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?

like image 514
patrickmesana Avatar asked Mar 14 '13 13:03

patrickmesana


People also ask

Does Socket.IO guarantee order?

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

How does socket IO client work?

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.

What is the difference between Socket.IO and socket IO client?

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).

Is Socket.IO emit asynchronous?

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.


1 Answers

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:

  • https://github.com/josephg/ShareJS/issues/375
  • Can websocket messages arrive out-of-order?
like image 53
Jeremy Blalock Avatar answered Oct 07 '22 01:10

Jeremy Blalock