User Datagram Protocol (UDP)

 

User Datagram Protocol (UDP)

Introduction

The User Datagram Protocol (UDP) is a connectionless and unreliable transport-layer protocol used in the Internet. It provides process-to-process communication by using port numbers, but it does not add any additional services to the Internet Protocol (IP) except changing communication from host-to-host to process-to-process communication.

Since UDP is connectionless, it does not establish a connection between the sender and the receiver before transmitting data. Each message is sent independently as a separate unit called a User Datagram.

UDP is considered an unreliable protocol because it does not guarantee that packets will reach the destination. It does not provide acknowledgments, retransmissions, sequencing, flow control, or congestion control. If a packet is lost or corrupted during transmission, UDP does not attempt to recover it.

Although UDP has these limitations, it offers significant advantages. It is a very simple protocol with minimum protocol overhead. If an application needs to send a small message and does not require reliable delivery, UDP is an excellent choice. Sending data using UDP requires much less interaction between the sender and receiver than using TCP, making UDP faster and more efficient for many real-time applications. Applications and services that use UDP are discussed later in this chapter.


UDP User Datagram

The data unit used by UDP is called a User Datagram.

A UDP user datagram consists of two parts:

  • Header
  • Data
+--------------------------+
|        Header            |   8 Bytes
+--------------------------+
|                          |
|         Data             |   8 to 65,535 Bytes
|                          |
+--------------------------+

The UDP header has a fixed size of 8 bytes and consists of four fields, each of 2 bytes (16 bits).


UDP Header Format

 0                15 16               31
+------------------+-------------------+
| Source Port      | Destination Port  |
+------------------+-------------------+
| Total Length     | Checksum          |
+------------------+-------------------+

Each field has a specific function.




1. Source Port Number

Size: 16 bits (2 bytes)

The Source Port Number identifies the application process that sends the UDP datagram.

  • It helps the receiver know which application originated the packet.
  • It is mainly used when the receiver needs to send a reply back to the sender.

Example

Source Port = 52100

means the datagram originated from the client application using port 52100.


2. Destination Port Number

Size: 16 bits (2 bytes)

The Destination Port Number identifies the application process that should receive the UDP datagram.

The operating system uses this port number to deliver the received data to the correct application.

Example

Destination Port = 53

indicates that the datagram is intended for the DNS service.


3. Total Length

Size: 16 bits (2 bytes)

The Total Length field specifies the total length of the UDP datagram, including both the header and the data.

Total Length=Header Length+Data Length\text{Total Length} = \text{Header Length} + \text{Data Length}

Since the UDP header is always 8 bytes, the data length can be calculated as

Data Length=Total Length8\text{Data Length} = \text{Total Length} - 8

A 16-bit field can represent values from 0 to 65,535 bytes. However, the actual maximum UDP datagram size is slightly less because the UDP datagram is encapsulated inside an IP datagram, whose total size is also limited to 65,535 bytes.


4. Checksum

Size: 16 bits (2 bytes)

The Checksum field is used for error detection.

It contains a value calculated from the UDP header and data. At the receiving end, the checksum is recalculated and compared with the transmitted checksum.

  • If the values match, the packet is accepted.
  • If they do not match, the packet is considered corrupted and is discarded.

The checksum is used only for error detection; UDP does not retransmit lost or corrupted packets.


Summary of UDP Header Fields

FieldSizeDescription
Source Port Number    16 bits    Identifies the sending application process
Destination Port Number    16 bits    Identifies the receiving application process
Total Length    16 bits    Specifies the total length of the UDP datagram (header + data)
Checksum    16 bits    Used for error detection

Example 

The following is the contents of a UDP header in hexadecimal format.

CB84 000D 001C XXXX

where

  • CB84 → Source Port Number
  • 000D → Destination Port Number
  • 001C → Total Length
  • XXXX → Checksum (value not required for this example)

(a) What is the Source Port Number?

The first four hexadecimal digits are

CB84

Converting hexadecimal to decimal,

(CB84)16=52100(CB84)_{16}=52100

Source Port Number = 52100


(b) What is the Destination Port Number?

The second four hexadecimal digits are

000D

Converting hexadecimal to decimal,

(000D)16=13(000D)_{16}=13

Destination Port Number = 13


(c) What is the Total Length of the User Datagram?

The third four hexadecimal digits are

001C

Converting hexadecimal to decimal,

(001C)16=28(001C)_{16}=28

Total Length = 28 bytes


(d) What is the Length of the Data?

The UDP header length is always 8 bytes.

Therefore,

Data Length=Total LengthHeader Length\text{Data Length}=\text{Total Length}-\text{Header Length}
=288=20 bytes=28-8=20 \text{ bytes}

Data Length = 20 bytes


(e) Is the Packet Directed from a Client to a Server or Vice Versa?

The destination port number is

13

Port 13 is a well-known port assigned to the Daytime service.

Since the destination is a well-known server port, the packet is traveling

Client  →  Server

(f) What is the Client Process?

Destination port 13 corresponds to the Daytime Protocol.

Therefore, the client is requesting the Daytime service.

Comments

Popular posts from this blog

Computer Networks PCCST501 Semester 5 KTU CS 2024 Scheme - Dr Binu V P

Introduction to Computer Networks

Introduction to Local Area Network (LAN)