What are UDP sockets

UDP - User Datagram Protocol

UDP is a connectionless transport protocol and works on layer 4, the transport layer, of the OSI layer model. It has a comparable task to the connection-oriented TCP. However, it works without a connection and is therefore insecure. This means that the sender does not know whether the data packets sent have arrived. While TCP sends confirmations when receiving data, UDP does not. This has the advantage that the packet header is much smaller and the transmission path does not have to transmit any confirmations.
Typically, UDP is used for DNS queries, VPN connections, audio and video streaming.

The User Datagram Protocol (UDP) on the TCP / IP protocol stack

layerServices / protocols / applications
applicationHTTPIMAPDNSSNMP
transportTCPUDP
InternetIP (IPv4 / IPv6)
Network accessEthernet, ...

How UDP works

UDP has the same task as TCP, only that almost all control functions are missing, making it leaner and easier to process.
UDP does not have any methods that ensure that a data packet arrives at the recipient. The numbering of the data packets is also omitted. UDP is not able to put the data packets together in the correct order. Instead, the UDP packets are forwarded directly to the application. The application is therefore responsible for secure data transmission.
As a rule, UDP is used for applications and services that can deal with packet loss or take care of connection management themselves. UDP is also suitable for applications that only need to transport individual, non-contiguous data packets.

Application support through ports (application support)

What UDP and TCP have in common is the port structure, which enables multiple applications to have multiple connections over the network at the same time.
A number is stored in each UDP data packet that defines a port behind which an application or service is located that can listen to this port and receive the data. The port numbers start from 0 and are permanently assigned to an application up to port number 1.023. The port numbers up to 49.151 are registered for applications. All port numbers above can be used freely. For example as the sender port number. The recipient of a data packet sends the data packets back to this port.
The port structure ensures that the data packets are passed on to the correct application.

Structure of the UDP header


UDP packets are made up of the header area and the data area. The header contains all the information that allows a reasonably orderly data transmission and that allows a UDP packet to be recognized as such. The UDP header is divided into 32-bit blocks. It consists of two such blocks, which contain the source and destination port, the length of the entire UDP packet and the check sum. The UDP header is very slim with a total of 8 bytes and can be processed with little computing power.

Meaning of the fields in the UDP header

Field contentbitdescription
Source port
(Source port)
16This is the source port from which the application sends the UDP packet. If the number of digits is 16 bits, the highest port is 65535.
Destination port
(Destination port)
16Here is the destination port via which the UDP packet is delivered to the application. If the number of digits is 16 bits, the highest port is 65535.
length16This field indicates how long the entire UDP packet is. This value can be used to determine the completeness of the UDP packet.
Check sum16This field is used to check whether the UDP packet was transmitted without errors. The check sum does not offer any protection against data loss.

Applications of UDP

As a rule, UDP is used for applications and services that can deal with packet loss or take care of connection management themselves. DNS queries, VPN connections, audio and video streaming are typical. UDP is also suitable for application protocols whose data volume fits into a data packet. For example, with a DNS request. Here it is not worthwhile to establish a connection first and then to disconnect it again later. If this one data packet is lost, you simply make the DNS request again.

Tunnel protocols, not only for VPN, usually use UDP instead of TCP. This is because the payload of the application protocols is already packed in TCP packets and it makes no sense to pack them again in TCP packets. In such a case, TCP optimizations such as Slow Start and Congestion Window have a negative effect on each other.
In addition, when using a TCP tunnel, applications could not use real-time-oriented protocols. Such as audio and video streaming. Here you have to rely on continuous data transmission, which is not possible with TCP, because the data only flows here when confirmation packets come back.
UDP is much more suitable for real-time applications because there is no limiting connection management here.

Other related topics:

share

Product recommendations

Everything you need to know about networks.

Network technology primer

The network technology primer is a book about the basics of network technology, transmission technology, TCP / IP, services, applications and network security.

I want that!

Everything you need to know about networks.

Network technology primer

The network technology primer is a book about the basics of network technology, transmission technology, TCP / IP, services, applications and network security.

I want that!