0
votes

by TCP socket programming: on my application, receiver side uses a small size buffer then transmitted data. So recv() is called several times til all data is received. On each call of recv(), used buffer is copied to another big buffer or appending to a file partly.

My question here is, should I handle the received TCP "packet order" in my code additionally, or TCP handles it on its own buffer on the background? Because transmitted TCP packets arrive to the receiver side not in a correct order.

1
TCP ensures data arrives in the same order it was sent. If you are observing otherwise, there is a bug in your code somewhere.nos
A common misunderstanding for those new to TCP is they expect messaging (i.e. each call to Send at one end will be matched by one call of Receive at the other end). If that's what you thought you were getting, perhaps you're just misinterpreting what you're seeing as "packets arriving out of order", which as others have mentioned, doesn't happen.Damien_The_Unbeliever

1 Answers

1
votes

My question here is, should I handle the received TCP "packet order" in my code additionally

No. TCP guarantees that it will handover the data to the application in the order it is received. Application need not implement the logic to ensure the order of data reception. Review your application code again for any bugs which is resulting in the received data being not in the same order it was sent.