Can websocket messages arrive out-of-order?

前端 未结 3 783
夕颜
夕颜 2020-12-03 00:35

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 differ

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 01:11

    At the network layer TCP is suppose to guarantee that messages arrive in order. At the application layer, errors can occur in the code and cause your messages to be out of order in the logic of your code. It could be the network stack your application is using or your application code itself.

    If you asked me, can my Node.js application guarantee sending and receiving messages in order? I'm going to have to say no. I've run websocket applications connected to WiFi under high latency and low signal. It causes very strange behavior as if packets are dropped and messages are out of sequence.

    This article is a good read https://samsaffron.com/archive/2015/12/29/websockets-caution-required

提交回复
热议问题