Is TCP Guaranteed to arrive in order?

前端 未结 4 1307
醉梦人生
醉梦人生 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:58

    TCP is connection-oriented and offers its Clients in-order delivery. Of course this applies to the connection level: individual connections are independent.

    You should note that normally we refer to "TCP streams" and "UDP messages".

    Whatever Client library you use (e.g. Twisted), the underlying TCP connection is independent of it. TCP will deliver the "protocol messages" in order to your client. By "protocol message" I refer of course to the protocol you use on the TCP layer.

    Further note that I/O operation are async in nature and very dependent on system load + also compounding network delays & losses, you cannot rely on message ordering between TCP connections.

提交回复
热议问题