tags:

views:

29

answers:

1

I'm developing C++ application server and client which use TCP. I have three messages on server: A, B and C. They are sent sequentially: A -> B -> C. And clients responses acknowledge messages:rA, rB, rC.

Do client receive A, B and C in order A->B-C? Do server receive rA->rB->rC?

Thanks in advance

+2  A: 

TCP guarantees that the order the packets are received (on a single connection) is the same as the order they were sent. No such guarantee if you've got multiple TCP connections, though - TCP preserves ordering only for the packets within a given TCP connection.

See the Wikipedia article on TCP for more overview.

One of the functions of TCP is to prevent the out-of-order delivery of data, either by reassembling packets into order or forcing retries of out-of-order packets.

Michael Petrotta
just to clarify "no such guarantee if you've got multiple tcp connections": TCP guarantees order over a particular connection, independently of all other connections. that means if you send A over the first connection and B over the second connection, they could be delivered in order or out of order. If you send them over the same connection, they'll be delivered in order.
atk
@atk: thanks; I clarified a little.
Michael Petrotta
Right. In particular, if you're creating separate connections for each message (as opposed to sending them sequentially over a single connection), they could arrive in any order.
David Gelhar