Let’s talk about UDP and compare it to TCP/IP, another populer internet communication protocol..
The synonym UDP stands for User Datagram Protocol.
It is a connection-less IP data transfer protocol.
But… what is connectionless?
Lemme explain, in a connectionless protocol the sender and the receiver don’t need to establish a connection before they could start a data transfer.
For example if you want to talk to a stranger in real life, you’ll need to shake hands and introduce yourself before starting the conversation.
This is the way TCP/IP protocol works.
If you and the stranger were computers communicating through UDP, you won’t need to shake hands and have an introduction. You can just start talking.
The heart of user datagram protocol is “the datagram”
It is the basic unit of data transfer in UDP
A UDP datagram contains information about the IP address & port number of the host machine which is supposed to receive it, and a payload which has to be delivered.
Everything is in binary format and… represented by bytes.
A datagram is sent by a host computer as one unit and it is received by the target computer as one unit.
A good example will be like putting a letter in an envelope
writing an address and port number as well on the envelope
Giving it to the postal service so that the intended receiver would pick it up.
An envelope here is the datagram.
Now let’s talk about a unique capability of UDP, that is … Datagram Broadcasting....
Since UDP is a connectionless protocol, as I explained earlier.
No hand shakes are needed
A host can send a packet to all hosts in the network on a specific port number at once in broadcast mode.
This would be akin to picking up a megaphone and talking to everybody in a hall at once.
In case of broadcast, The IP address part of the datagram is set to all 1s and a port number is also supplied
Any other host in the same local area network listening on the specific port number can receive this packet.
We can say it will be akin to putting a letter in an envelope and writing the address “everybody ” on it.
UDP broadcast is a feature used by many network protocols such as Simple Network Monitoring Protocol or SNMP.
I must tell you about some other important details of UDP protocol as well.
First, the delivery of a datagram is not guaranteed in UDP.
This means that if a packet is not received on the client, the network will not be flooded with re-transmission packets.
That’s why UDP is used for applications like video and audio conferencing, and IP TV.
A few missed packets will cause a some squeaks in the voice or maybe a few distorted pictures.
But the network won’t be congested with additional packets just to make sure you don’t miss a frame while binging on Netflix.
This is different from TCP/IP, in which case there’s an elaborate system of acknowledgements and retransmissions to make sure that all data sent is delivered successfully.
Secondly, the sequence of arrival of datagrams on the receiver can be different from the sequence of sending.
Both of these characteristics make UDP a faster protocol as compared to the TCP/IP.
Anyhow, both TCP/IP and UDP have their own areas of application.
Their own strengths and weaknesses.
And one size doesn't fit all in this case.
Since we’re already talking about TCP/IP protocol. It is worth mentioning that in case of TCP/IP protocol the sender and receiver must establish a connection before they could start a data exchange.
TCP/IP can’t do broadcasting and multicasting.
Multicasting happens when a sender can send one datagram to multiple well known hosts, this is useful in IPTV scenarios.
Now that you got the basics covered about network programming. Let’s move on to the next section where we’d crank some code.
You don't need to learn C to work on this course.
Socket Java, python socket udp