What are some approaches to make sure UDP delivers packets in order?

390 Views Asked by At

I read that application can handle in order delivery of udp. But how does that work? There is no sequence number or anything to determine if a packet is out of order.

1

There are 1 best solutions below

0
Steffen Ullrich On

What are some approaches to make sure UDP delivers packets in order?

This is the wrong approach to the problem. You cannot guarantee a specific delivery order of packets and neither you can make sure that packets are not lost or that packets get duplicated. Instead you need to check the successful delivery and delivery order in your recipient application and react to transmission problems by ignoring duplicates, processing messages in the intended order or if necessary ask the sender for a retransmit of a lost message.

The typical way to do this is to add some sequence number to the message and then check this sequence number in the recipients application. This is for example done with RTP (UDP based protocol for real time audio/video/...) which has a 16 bit sequence number in the RTP header. Similar QUIC has a 32 bit sequence number in each frame.

The same approach is actually used with TCP which uses a 16 bit sequence number. Only that with TCP the logic for reordering and retransmits is usually done inside the recipients OS kernel and not inside the recipients application.