Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The order of TCP message?

Tags:

tcp

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?

like image 547
user469786 Avatar asked Oct 08 '10 02:10

user469786


1 Answers

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.

like image 91
Michael Petrotta Avatar answered Oct 20 '22 11:10

Michael Petrotta