User Datagram Protocol (UDP) explained

User Datagram Protocol (UDP) is an optional communications protocol for data transmission. It is used mostly for establishing low-latency and loss-tolerant connections between applications on the internet. The IP address works with TCP and UDP, sometimes called TCP/IP and UDP/IP. Both TCP and UDP send short packets of data called datagrams.
User Datagram Protocol (UDP) Low Overhead vs Reliability
User Datagram Protocol provides the basic transport layer functions. It sends the packets with lower bandwidth overhead and latency than TCP. User Datagram Protocol (UDP) is not a connection-oriented protocol, so it does not offer sophisticated retransmission, flow control, and sequencing mechanisms for lost and out-of-order packets. So, the User Datagram Protocol (UDP) is less reliable than TCP. However, this does not mean that applications that use the User Datagram Protocol (UDP) are forever unreliable and substandard. It only means that the transport layer protocol does not provide these functions and must be implemented in a different place if required.

Because of low overhead, UDP is the best protocol for network applications in which apparent latency is critical, such as gaming, voice, and video communications, which can bear some data loss without badly disturbing apparent quality. Like TCP, UDP does not set up a connection before sending data, it just starts sending data when required.
UDP Datagram reassemble
UDP datagrams arrive at the destination using different routes and arrive in the wrong order. The UDP does not follow sequence numbers, just like TCP. It has no mechanism to reorder the datagram into their transmission order. So, the UDP reassembles the data in the exact order. If the sequence is important to the application, the application should identify the right sequence number and decide how the data should be processed.

UDP Server Processes and Requests
UDP-based server applications assign well-known or registered port numbers just like TCP. When these applications and processes run on a server, they accept the data matched with the assigned port number. When UDP receives a datagram destined for one of these ports, it forwards the application data to the proper application based on its port number.

UDP Client Processes
The client application will ask a server process to start communication between the server and the client. The UDP client selects a port number from the range of port numbers randomly. The destination port on the server is generally the well-known or registered port number assigned to the server process. Once the client selects the source and destination ports, the header of all datagrams uses this selected pair of ports. The destination and source port are reserved for the datagram header when returning the data from the server to the client.
FAQs
What is the User Datagram Protocol (UDP)?
UDP is a communication protocol that sends messages (datagrams) without establishing a connection.
What are the advantages of using UDP?
UDP is faster and more efficient than TCP for certain applications because it doesn’t require connection setup or error correction.
In what scenarios is UDP preferred over TCP?
UDP is preferred in time-sensitive applications like video streaming, online gaming, and voice over IP (VoIP) where speed is crucial and some data loss is acceptable.
Does UDP guarantee data delivery?
UDP does not guarantee data delivery, ordering, or protection against duplicates.
How does UDP handle error detection?
UDP uses checksums for data integrity but relies on the application layer for error correction.