TCP & UDP Explained

Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are foundational pillars of the internet, enabling different types of data transmission from a network source to the destination. Read more for more details.

Jan 15, 2023 - 16:19
TCP & UDP Explained
TCP/IP vs. UDP

WHAT IS TCP / IP ?

TCP/IP stands for Transmission Control Protocol/Internet Protocol. It is a set of networking protocols that are used to connect devices on a computer network. It is the foundation of the internet and allows devices to communicate with each other by defining how data is sent and received, and how devices are addressed and routed on the network.

TCP is responsible for establishing a reliable connection between devices and ensuring that data is sent and received in the correct order. It also retransmits any lost or corrupted data packets.

IP is responsible for addressing and routing packets of data between devices. It uses IP addresses to identify devices on the network and to determine the best path for data to travel.

Together, TCP/IP provides a complete set of rules and procedures for data communication on a network, including the internet.

As a connection-oriented protocol TCP establishes a reliable connection before sending data. The process of establishing a TCP connection is known as the three-way handshake and it includes the following steps:

  1. Connection initiation: The client device sends a packet with the SYN (Synchronize) flag set to 1 to the server device, which is attempting to initiate a connection. This packet is known as a SYN packet.

  2. Server response: The server device receives the SYN packet and sends back a packet with both the SYN and ACK (Acknowledgment) flags set to 1. This packet is known as a SYN-ACK packet and it indicates that the server is ready to communicate and acknowledges the receipt of the SYN packet.

  3. Client response: The client device receives the SYN-ACK packet and sends a packet with the ACK flag set to 1 back to the server. This packet is used to confirm that the client has received the SYN-ACK packet and that the connection has been established.

Once the three-way handshake is complete, the devices can start exchanging data over the established connection. The client and server can also use the ACK flag to acknowledge the receipt of data packets and to retransmit any packets that are lost or corrupted.

This three-way handshake process is a reliable way to establish a connection between two devices, it ensures that both devices are ready to communicate, the sequence numbers are set and the devices have the correct information to communicate with each other. It also allows devices to start and end the connection in a controlled manner.

WHAT IS UDP ?

User Datagram Protocol (UDP) is a connectionless & unreliable protocol that belongs to the family of IP protocols, similar to TCP. Unlike TCP, UDP does not establish a connection before sending data and does not guarantee that the data sent will be received by the intended recipient.

UDP is a simpler protocol than TCP, it does not have the overhead of establishing and maintaining a connection, it is faster and have less latency. UDP is generally used for real-time applications such as online games, video streaming, and voice over IP (VoIP) where the speed of transmission is more important than the reliability of the data.

The packets are also called datagrams and they have a smaller header than TCP and include the source and destination port numbers, which are used to direct the datagram to the correct application or process on the receiving device.

As mentioned earlier UDP does not establish a connection before sending sending data. So the data transer process is quite different. And finally we can say UDP does not use a handshake protocol.

Instead, UDP simply sends packets of data, called datagrams, to the destination IP address and port specified in the packet header. The recipient receives the datagram, but there is no guarantee that the datagram was received, or that it will be received by the intended recipient.

Additionally, there is no mechanism for resending lost or corrupted datagrams. Because of this, UDP is considered to be an unreliable protocol and is typically used for real-time applications where the speed of transmission is more important than the reliability of the data.

TCP vs. UDP

TCP and UDP are two of the most commonly used protocols for transmitting data over a network. The main differences between the are:

  • Connection-oriented vs Connectionless: TCP is a connection-oriented protocol, which means it establishes a reliable connection before sending data. This connection is maintained throughout the duration of the communication, and the devices can exchange multiple packets of data. On the other hand, UDP is a connectionless protocol, which means it does not establish a connection before sending data. Instead, it simply sends packets of data, called datagrams, to the destination IP address and port specified in the packet header.

  • Reliability: TCP guarantees that data sent will be received by the intended recipient and that the data received will be the same as the data sent. If packets are lost or corrupted, TCP will resend them until they are received successfully. UDP, on the other hand, is an unreliable protocol and does not guarantee that data sent will be received or that the data received will be the same as the data sent.

  • Flow Control: TCP uses a flow control mechanism to prevent the sender from overwhelming the receiver with too much data. It uses a sliding window algorithm that allows the sender to send a certain number of packets, then wait for an acknowledgement from the receiver before sending more. UDP does not have flow control mechanism.

  • Overhead: TCP has more overhead than UDP because of the additional information that is sent in the packet headers to establish and maintain a connection.

  • Use case: TCP is used for applications that require guaranteed delivery of data, such as file transfer, email, and web browsing. UDP is used for real-time applications that require fast, efficient transmission of data, such as online games, video streaming, and voice over IP (VoIP).

In summary, TCP is a reliable, connection-oriented protocol with more overhead than UDP, that is well suited for applications that require guaranteed delivery of data, while UDP is an unreliable, connectionless protocol with less overhead that is well suited for real-time applications that require fast, efficient transmission of data.

WHICH ONE TO USE ? 

Although diffrences are explained well and it means it that is easy to pick which protocol to use, actually it is not that clear. It's worth noting that some application or services may use a combination of both TCP and UDP to provide a balance of reliability and speed.

As a video streaming platform YouTube should use UDP according to definitions. But YouTube does not use only TCP for connection. 

YouTube uses a combination of both TCP and UDP for streaming videos.

  • TCP is used for the initial handshake between the client and the server to establish a connection and to exchange control information such as the client's preferred video quality and the available bandwidth. This connection is maintained throughout the duration of the video streaming, and the server can use it to adapt the video quality to the client's changing network conditions.
  • UDP is used for the actual video streaming once the connection has been established. Because UDP is a connectionless, unreliable protocol, it allows for faster and more efficient transmission of video data. It does not guarantee that all the packets will be received by the client, but it does not require the overhead of re-transmission of lost packets, which is not critical for video streaming since the human eye can't perceive all the missing frames.

Additionally, YouTube also uses other technologies such as Adaptive bitrate streaming and WebRTC to provide a smooth streaming experience to the users. Adaptive bitrate streaming allows YouTube to adjust the video quality based on the viewer's network conditions, while WebRTC is a real-time communication technology that enables low-latency video and audio streaming.

In summary, YouTube uses a combination of TCP and UDP to provide a smooth streaming experience to users. TCP is used for the initial connection establishment and control information exchange, while UDP is used for the actual video streaming.

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow