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 not a Twisted-specific example, because it should conform to the TCP standard, but if anyone familiar with Twisted could provide a Twisted-specific answer for my own peace of mind, that'd be appreciated :-)
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".
If too many packets are received out of order, TCP will cause a retransmission of packets similar to what happens with dropped packets. As such, the impact of out of order packets on goodput is similar to the impact of packet loss.
Out-of-order delivery can be caused by packets following multiple paths through a network, by lower-layer retransmission procedures (such as automatic repeat request), or via parallel processing paths within network equipment that are not designed to ensure that packet ordering is preserved.
It is not generally a problem. It probably indicates there are multiple paths between source and destination - and one travels a through a longer path. It means TCP has slightly more work to reassemble segments in the correct order.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With