A User Datagram Protocol (UDP) socket is a type of computer protocol used to transmit and receive information over a network. UDP sockets are known for their connectionless nature, which means that they do not need to contact another server before attempting to send data. This is very different from Transmission Control Protocol (TCP) sockets, which must maintain a communication line with another socket at all times. Many Internet applications regularly use a UDP socket for communication because it allows large numbers of users to access online servers without the need for ongoing communication.
Woman doing handstand with a computer
The three types of computer sockets are UDP, TCP, and raw. Raw sockets are most often used to help locate or direct network traffic. TCP sockets are used when it is important that all information reaches the destination socket in the order it is sent. UDP sockets are used when information needs to be retrieved from a server in small batches using individual packets called datagrams.
One of the disadvantages of using a UDP socket is what is called packet loss, there is no pre-established connection between the two sockets, so there is a chance that a datagram may not reach the destination socket. The destination computer has no idea that the packet is coming and will not request that it be resent, so the data is completely lost.
Systems using a UDP socket framework often opt for packet loss rather than the transmission problems that a TCP connection can cause. An example is a critical real-time system where it is more important to keep data flowing in and out of the system rather than having the entire system potentially paused due to a slow TCP connection. Alternatively, TCP connections are used in situations where any data loss can compromise the integrity of the system.
Creating a UDP socket is very easy. Since you don’t need a dedicated computing process to constantly maintain the port that the socket is connected to, it requires very little overhead. Sending and receiving datagrams over a UDP socket is equally easy due to the minimal size and low complexity of the packet structure.
Many vital online services use UDP sockets for communications. The Domain Name System (DNS), which converts simple Internet addresses that people can read and understand into a long string of numbers, uses UDP sockets because only one request per user is typically required at a time. Streaming media services also use UDP, because the loss of a single packet does not interrupt the entire stream in most cases.