Reputation: 135
I am writing a c++ socket program for client and server ,should I keep the packets in a specific order or it will remain the same order they had been sent? thanks in advance.
Upvotes: 1
Views: 738
Reputation: 84159
TCP socket abstraction gives you a bi-directional reliable stream of bytes, so data will arrive in the same order you send it. The caveat though is that TCP does not know about your application-level message boundaries - you have to make sure you know how to detect and buffer partial messages on the receiving side.
Upvotes: 2
Reputation: 21900
If you're using TCP, then packet ordering is handled by it. That means that if you open a socket and send A, B, and then C, the other socket's end will receive A, B, and then C.
On the other hand, if you're using UDP, then there is no such guarantee.
Upvotes: 1