Jump to content
  • Advertisement
Sign in to follow this  
zigzag32

TCP packets ordering

This topic is 4020 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Lets say a client sends a sequence of n-bytes-sized packets using a tcp socket. The server is receiving the packets bytes in either smaller sizes chunks or even combined chunks that may contain more than a packet and a fraction...or wahtever combination possible caussed by a mess on the network or trafic... My question is the order of bytes preserved? so that we can reconstruct the packets easily on the other side? could a situation happen where portion of packet A arrives and then portion of packet B, followed by portion of A? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by zigzag32
My question is the order of bytes preserved?

Yes. That is exactly what is preserved.

Share this post


Link to post
Share on other sites
Quote:
Original post by zigzag32
Is it the same for UDP? If not how can I reorder or figure out which bytes belong to which packets?


By labeling them with a sequence index.

With UDP you also need to take care of lost/duplicate packets, as well as manual splitting and re-assembly for packets that exceed the MTU.

In other words, you need to re-invent the TCP.

Share this post


Link to post
Share on other sites
Quote:
Original post by zigzag32
Is it the same for UDP? If not how can I reorder or figure out which bytes belong to which packets?


The only guarantee UDP makes is that if you receive a packet, it will be in tact. That is, if it receives a partial packet, it will drop it. So, basically, byte order will be preserved because you will not get partial UDP packets.

Note: It's still possible you can get packet B before packet A, and all that fun stuff.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!