UDP

Hi it’s the user datagram protocol!

Unit Goals

To understand the role of UDP in a network and appreciate the simplicity of its packet format.

What UDP Is

It’s known as the IP of the transport layer, or “IP between applications.”

Like IP, it is:

What UDP is Used For

UDP is used for applications that just send messages back and forth, not streams.

There are no sequence numbers. If an application wants to sequence messages, then the application has to put sequence numbers in the packet body and the application has to do the reordering and re-transmission.

Applications that might use UDP:

If you need streams, reliability, and all that, use TCP instead.

So why might UDP be good? Well, it’s really fast as there’s very little overhead.

UDP Packet Format

UDP is a transport layer protocol, so it only cares about port numbers, not about networks and hosts. As a message-based protocol, there is no notion of sequence numbers, fragments, or really anything else. The packet format is just this:

0
0
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
2
5
2
6
2
7
2
8
2
9
3
0
3
1
Source Port Destination Port
Message Length Checksum

Body

Discussion:

Exercise: Do some research to find out exactly how the UDP Header Checksum is computed.
Choose message sizes wisely

Although messages can be up to 64K in size, if you make them too big they will get fragmented at the IP layer. Remember that IP fragments in order to fit its packets in the source and destination’s networks’ frames, so generally keep the UDP messages around 1400-1450 bytes (leaving room for the IP header, etc.)

Using UDP in Applications

UDP applications may be client-server or peer-to-peer.

Python

TODO

Java

TODO

JavaScript

TODO

Summary

We’ve covered:

  • What UDP is
  • What UDP is for
  • The UDP packet format