Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can websocket messages arrive out-of-order?

If we send two messages over the same html5 websocket a split millisecond apart from each other,

Is it theoretically possible for the messages to arrive in a different order than they were sent?

like image 662
Alex Lopatin Avatar asked Aug 03 '12 23:08

Alex Lopatin


People also ask

Can WebSocket messages get lost?

Websocket client connections may drop due to intermittent network issue and when connections drop, messages will also be lost. In a pubsub system, publishers are decoupled from subscribers, so publishers hard to detect subscribers' drop or message loss.

Can WebSockets be load balanced?

Despite its obvious benefits, there remain some concerns with utilizing WebSockets for load balancing. For example, if a WebSocket-based app is running on two servers and the load balancer is distributing connections evenly across them, it won't distribute any of the existing traffic when a third server is added.

Does WebSocket guaranteed delivery?

There is no guarantee of the successful delivery of a web socket message to the peer, but if the action of sending a message causes an error known to the container, the API throws it.


2 Answers

Short answer: No.

Long answer:

WebSocket runs over TCP, so on that level @EJP 's answer applies. WebSocket can be "intercepted" by intermediaries (like WS proxies): those are allowed to reorder WebSocket control frames (i.e. WS pings/pongs), but not message frames when no WebSocket extension is in place. If there is a neogiated extension in place that in principle allows reordering, then an intermediary may only do so if it understands the extension and the reordering rules that apply.

like image 192
oberstet Avatar answered Sep 26 '22 22:09

oberstet


It's not possible for them to arrive in your application out of order. Anything can happen on the network, but TCP will only present you the bytes in the order they were sent.

like image 24
user207421 Avatar answered Sep 24 '22 22:09

user207421