Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Does TCP/UDP protocol always send or receive file packets sequentially? Would it possible to make a choice which data packets will be sent first using sockets API?

share|improve this question
1  
Packets are sent sequentially. UDP however does not guarantee nor the order of received packets nor delivery itself (en.wikipedia.org/wiki/User_Datagram_Protocol). Why do you need to reorder stream at socket level (after you written the data)? That seem weird since sending data in order you need is most natural choice anyway. –  Petr Gladkikh Dec 19 '11 at 7:42
add comment

1 Answer

up vote 9 down vote accepted

Neither TCP nor UDP can guarantee packets arrive at their destination in sequence because they both use IP packets, and IP doesn't do any sequencing.

With UDP, there are two separate issues. One is the order of the packets that comprise a single datagram. You can't control this, and every implementation I know of will send them in order.

However, you can send your datagrams in whatever order you want. The individual fragments that comprise a datagram will be re-ordered by the receiver to reconstruct the original datagram. Datagrams received out of order (not in the order they were sent) will be passed to the application in the order they were received. A datagram is considered received when the last fragment required to re-construct it is received. Datagrams will be passed to the application as they are completed, regardless of the order they were sent.

With TCP, the implementation controls the formation of packets. You can't really control it at all. Every implementation I know of will send them in order. They are required to re-order them if they are received out of order.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.