User Datagram Protocol (UDP)
- It is a simple transport layer protocol designed to send data packets over the Internet.
- It takes the datagram from the network layer, attaches its header, and sends it to the user.
- It is a connectionless, stateless, and unreliable protocol.
- But it is a fast protocol that offers minimal transport service.
- It uses different port numbers so that the data can be sent to the correct destination. The port numbers are defined between 0 and 1023.
- It is almost a null protocol that does not guarantee in-order delivery and does not provide a congestion control mechanism.
- It does not have any acknowledgment mechanism. Therefore there is no handshaking between the sender and the receiver sides.
- It is a beneficial protocol when data flows in one direction only and when acknowledgment of data does not hold any significant importance.
- UDP is majorly used for streaming applications such as VoIP, multimedia streaming.
Need of UDP
- TCP generates overhead for certain kinds of applications.
- The Connection Establishment and Connection Termination phases of TCP consume most of the time
- To avoid all these some applications require fast speed and less overhead therefore UDP is established.
UDP Header Format
- UDP header has a fixed 8-bytes size simple header.
- The first 8 Bytes contain all necessary header information and the remaining part consists of data.
- UDP port number fields are each 16 bits long, therefore the range for port numbers is defined from 0 to 65535. In that port number 0 is reserved.
- Port numbers help to differentiate several user requests or processes.
The UDP header contains four fields are as follows:
1] Source Port
- Source Port is a 16-bit field.
- It identifies the port of the sending application.
- This field can be set to zero if the destination computer doesn’t need to reply to the sender.
2] Destination Port
- Destination Port is a 16-bit field.
- It identifies the port of the receiving application.
3] Length
- Length is a 16-bit field.
- It identifies the combined length of UDP Header and Encapsulated data.
- The limit for the UDP length field is determined by the underlying IP protocol used to transmit the data.
4] Checksum
- The checksum is a 16-bit field used for error control.
- It is calculated on UDP Header, encapsulated data, and IP pseudo-header.
- Checksum calculation is not mandatory in UDP.
- It is an optional field, depending upon the application, whether it wants to write the checksum or not.
- If it does not want to write the checksum, then all the 16 bits are zero; otherwise, it writes the checksum.