Is TCP Guaranteed to arrive in order?

前端 未结 4 1305
醉梦人生
醉梦人生 2021-02-01 14:24

If I send two TCP messages, do I need to handle the case where the latter arrives before the former? Or is it guaranteed to arrive in the order I send it? I assume that this is

4条回答
  •  一向
    一向 (楼主)
    2021-02-01 14:52

    As long as the two messages were sent on the same TCP connection, order will be maintained. If multiple connections are opened between the same pair of processes, you may be in trouble.

    Regarding Twisted, or any other asynchronous event system: I expect you'll get the dataReceived messages in the order that bytes are received. However, if you start pushing work off onto deferred calls, you can, erm... "twist" your control flow beyond recognition.

提交回复
热议问题