Two weeks ago I published an article about TCP.
Having a single article, about TCP isn't nice.
So here's another one this time about UDP.
Today you will learn:
- How does the UDP protocol work
- The packet format that UDP protocol uses
- Applications behind the UDP protocol
UDP which stands for User Datagram Protocol is one of the main protocols of the internet protocol suites.
But some of you may ask?
"What is a protocol?"
A protocol is essentially a set of rules that allows two computers to talk to each other.
There can be many different sets of rules, hence we have many different protocols.
UDP is one of them.
But what makes UDP different?
Short Answer: UDP is stateless, meaning it doesn't save any state between the client and server, it also is very light making it fast, but the downside is that it's not reliable, packets can go missing, corrupted, etc...
Long Answer: Read on...
In our last article about TCP, we found out that TCP has a ton of headers.
Unlike TCP, UDP is light, hence having the minimal amount of headers.
Let's quickly go over each field:
- Source Port — The sending device port.
- Destination Port — The receiving device port.
- Length — This field specifies the length in bytes of the UDP header and UDP data.
- Checksum — Indicates whether the header was damaged in transit.
- Data — The actual info that your sending
To be honest, there isn't much to say so let's condense the features of UDP in a list:
- UDP does not acknowledge packets, so if data goes missing, it won't be retransmissioned.
- UDP is a good protocol for data flowing in one direction
- UDP is simple and suitable for query-based communications.
- UDP is stateless, so it basically doesn't save any state between the client and server.
- UDP does not provide congestion control, meaning that it doesn't regulate the amount of data is being sent over.
- UDP does not guarantee the orderliness of data
It sounds like I'm talking about the cons of UDP, but there are in fact many use cases for it. For one it's simple and two it's fast.
- Streaming Media — Streaming sites are fine with loss packets, if one frame is lost in a video it won't affect the quality much, but what's important is speed. This is why UDP is a good protocol for streaming media.
- Domain Name Servers — This is used to get the IP address from domains for example www.google.com leads to 126.96.36.199. This works well using UDP because queries must be fast and only consist of a single request followed by a single reply packet.
- VPN - Some VPN systems such as OpenVPN may use UDP and perform error checking at the application level while implementing reliable connections.
Congratulations, you are one step closer in being a better developer!
This was a pretty short post, there isn't much to say (surface-level) about UDP, but either way I hope you enjoyed today's article.
If you enjoy my content, I have more in my personal blog, you can check it out here.
Also, I tweet snippets of useful stuff over twitter @tamerlan_dev
Thanks For Reading!!