Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ensuring packet order in UDP

I'm using 2 computers with an application to send and receive udp datagrams. There is no flow control and ICMP is disabled. Frequently when I send a file as UDP datagrams via the application, I get two packets changing their order and therefore - packet loss.

I've disabled and kind of firewall and there is no hardware switch connected between the computers (they are directly wired).

Is there a way to make sure Winsock and send() will send the packets the same way they got there?

Or is the OS doing that?

Or network device configuration needed?

like image 892
Davidallencoe Avatar asked Sep 19 '10 09:09

Davidallencoe


People also ask

Does UDP guarantee packet order?

Unlike TCP, UDP doesn't guarantee the packets will get to the right destinations. This means UDP doesn't connect to the receiving computer directly, which TCP does. Rather, it sends the data out and relies on the devices in between the sending and receiving computers to correctly get the data where it's supposed to go.

How UDP packets are ordered?

Conversely from TCP, UDP does not guarantee a reliable or ordered delivery of the packets. Indeed, if you look at the UDP header there is nothing such as Sequence Number or Acknowledgment Number. Note also that using UDP does not mean that an ordered delivery of packets to the application layer cannot be achieved.

Can UDP packets be sent out of order?

UDP Traffic: Out-of-order packets can also be caused by UDP traffic. This issue occurs primarily due to stateless connections and the lack of flow control mechanisms that exist within UDP protocol.


3 Answers

UDP is a lightweight protocol that by design doesn't handle things like packet sequencing. TCP is a better choice if you want robust packet delivery and sequencing.

UDP is generally designed for applications where packet loss is acceptable or preferable to the delay which TCP incurs when it has to re-request packets. UDP is therefore commonly used for media streaming.

If you're limited to using UDP you would have to develop a method of identifying the out of sequence packets and resequencing them.

like image 72
PaulG Avatar answered Oct 04 '22 17:10

PaulG


UDP does not guarantee that your packets will arrive in order. (It does not even guarantee that your packets will arrive at all.) If you need that level of robustness you are better off with TCP. Alternatively you could add sequence markers to your datagrams and rearrange them at the other end, but why reinvent the wheel?

like image 27
crazyscot Avatar answered Oct 04 '22 17:10

crazyscot


is there a way to make sure winsock and send() will send the packets the same way they got there?

It's called TCP.

Alternatively try a reliable UDP protocol such as UDT. I'm guessing you might be on a small embedded platform so you want a more compact protocol like Bell Lab's RUDP.

like image 24
Steve-o Avatar answered Oct 04 '22 15:10

Steve-o