Foundations of Connection

Foundations of Connection

Exploring TCP vs. UDP: Key Differences Between the Transport Layer's Most Popular Protocols

What is protocol?

In simple words, we can say a protocol means some simple rules to follow. In the context of communication, a protocol is the set of rules that govern communication and interaction between different entities. In networking, a protocol is a set of rules for formatting and processing data and sharing information between them.

Network protocols are like a common language for computers. Imagine how people from different parts of India speak various languages, but they still manage to talk to each other using a common language like Hindi or English.

Similarly, two computers can easily share information with each other if they both use the Internet Protocol (IP). Even if they have different hardware and software, they can still communicate smoothly because they use the same set of rules, or protocols.

Protocols can operate on different layers of a network. These layers are primarily represented by two models: the OSI (Open Systems Interconnection) model and the TCP/IP model.

In the OSI model, each layer has specific responsibilities for tasks related to communication. For example, the Internet Protocol (IP) works on the network layer and is responsible for creating an IP address (an IP address is a unique numerical identifier assigned to each device connected to a network, enabling communication between them) and managing the routing mechanism. Meanwhile, the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) work on the transport layer.

What are the seven layers of the OSI model?

OSI stands for Open Systems Interconnection. It is a reference model that specifies standards for communication protocols and also defines the functionalities of each layer. The OSI model was developed by the International Organization for Standardization and consists of 7 layers. Each layer has different functionalities and follows different protocols. The 7 layers are as follows:

  1. Physical Layer: This layer is the first layer from the bottom in the OSI model and deals with the physical aspects of data transmission. On the sender's side, it converts the digital signal to analogue signals (in the form of 0s and 1s) and sends it to the receiver through a physical medium (e.g., copper cables, fiber optics, wireless signals). The receiver then converts the analogue signal back to a digital signal.

  1. Data Link Layer: The Data Link layer is the second layer from the bottom in the OSI model. Its major role is to ensure error-free transmission of information from one node to another. It handles the framing of data and is also responsible for encoding and decoding.

  1. Network Layer: The Network layer is the third layer in the OSI model of computer networks. Its main function is logical or IP addressing and transferring network packets from the source to the destination. It encapsulates data into packets and adds network addresses (e.g., IP addresses).

  1. Transport Layer: The Transport layer provides end-to-end communication services for applications. It ensures complete data transfer, error recovery, and flow control between hosts. This layer segments and reassembles data for efficient transmission and provides reliability with error detection and correction mechanisms. The Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) operate at this layer.

  1. Session Layer: The Session layer initiates and terminates connection sessions between two devices interacting on the network, ensuring that resources are neither overused nor underutilized. It facilitates synchronization, checkpointing, and recovery of data exchange.

    1. Presentation Layer: The Presentation layer prepares data for the Application layer by translating, compressing, and encrypting it.

  1. Application Layer: The Application layer is the topmost layer and provides network services directly to the end user or application. It includes protocols like HTTP (Hypertext Transfer Protocol), FTP (File Transfer Protocol), SMTP (Simple Mail Transfer Protocol), and DNS (Domain Name System).

How Communication Happens in the OSI Model – An Email Example

Suppose you send an email from Kolkata to Tokyo. Various OSI layers handle different parts of the communication process:

  1. Application Layer (Layer 7): You create the email using an app like Gmail, and it uses a protocol like SMTP (Simple Mail Transfer Protocol) to send it.

  2. Presentation Layer (Layer 6): The email gets formatted and possibly encrypted for safe transfer.

  3. Session Layer (Layer 5): A session is set up between your email server in Kolkata and the recipient's server in Tokyo, enabling communication between the two.

  4. Transport Layer (Layer 4): The email is broken down into smaller packets. TCP helps ensure these packets are delivered in the correct order without loss.

  5. Network Layer (Layer 3): Each packet is assigned an IP address, so it knows where it’s headed – in this case, to Tokyo.

  6. Data Link Layer (Layer 2): The packets move over local networks using MAC addresses, with error-checking mechanisms in place to ensure correctness.

  7. Physical Layer (Layer 1): The data is converted into electrical or analog signals and travels through physical cables (like fiber-optic) across the distance, possibly crossing the ocean.

Once the email reaches Tokyo, the process happens in reverse:

  1. Physical Layer: The electrical signals are received and converted back into packets.

  2. Data Link Layer: Any errors in the packets are fixed and passed on.

  3. Network Layer: Ensures the packets arrive safely at their destination.

  4. Transport Layer: The transport layer ensures the email packets are reassembled correctly.

  5. Session Layer: The session stays open until all data is received successfully.

  6. Presentation Layer: The email is decrypted (if necessary) and displayed in a readable format.

  7. Application Layer: Finally, the email appears in the recipient’s inbox in Tokyo.

Transport Layer

The transport layer ensures reliable and transparent data transfer between two systems. It ensures that data is not lost, misconfigured, or corrupted. The Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are the most widely used protocols operating at this layer. Each has its own advantages and disadvantages, which we will now discuss.

TCP — Transmission Control Protocol

TCP is a connection-oriented protocol, meaning it ensures communication between two devices (client and server) happens reliably, with proper error checking and acknowledgment. TCP guarantees that the data sent from the source arrives at the destination in the same order it was sent and without any errors. The primary features of TCP include:

  • Reliability: It guarantees that data will be received by the receiver accurately.

  • Sequencing: Data is delivered in the same order it was sent by the sender.

  • Error Detection: TCP checks if any error is present. To achieve this, TCP uses the checksum method.

  • Flow Control: TCP manages data transmission rates to avoid congestion in the communication path.

  • Congestion Control: TCP ensures that too much data is not sent at once, preventing the network from becoming overwhelmed.

Working of Transmission Control Protocol (TCP)

Transmission Control Protocol (TCP) breaks down data into small bundles (segmentation) and then reassembles the bundles into the original message at the other end to ensure that each message reaches its target location intact. Sending the information in small bundles is easier and more efficient than sending it all at once.

After a message is broken down into bundles, these bundles may travel along multiple routes to reach the same destination if one route is congested.

In TCP, the connection is established using a three-way handshake. The handshake involves three steps:

Three-Way Handshake

  1. SYN (Synchronize): The client sends the segment with its sequence number.

  2. SYN-ACK (Synchronize-Acknowledgment): The server, in turn, sends its segment with its own sequence number as well as the acknowledgment sequence, which is one more than the client's sequence number.

  3. ACK (Acknowledgment): Then the client sends the acknowledgment to the server.

In this way, the connection is established between the client and the server. Let’s break down each of these steps using an example of downloading a file to understand how the process works.

Example of Sending an Email using TCP

Sending an email is a process where your device (the email client) communicates with the server (like Gmail) that the email provider uses. Here’s a step-by-step explanation of how the TCP communication occurs:

1. Connection Establishment:
To ensure the email reaches its destination without issues, TCP handles the transfer reliably. It uses a three-way handshake to perform this task. This process helps ensure the email is sent correctly, even if there are some problems during transmission.

  • SYN (Synchronize):
    The email client sends a SYN packet to the email server with a sequence number to initiate the connection and notify the server that the client wants to send data.

  • SYN-ACK (Synchronize-Acknowledgment):
    The server receives the SYN packet and responds with a SYN-ACK packet, containing its own sequence number and an acknowledgment number (client's sequence number + 1). This way, the client knows that the server is ready to receive data.

  • ACK (Acknowledgment):
    The client receives the SYN-ACK packet and responds with an ACK packet, confirming the server’s sequence number. At this point, the connection is established, and data can be transferred.

2. Data Segmentation:
Once the connection is established, the email client sends the email message to the server. The email is sent using small segments. Each segment contains two parts: first, the actual email content (payload), and second, the header information.

3. Data Reassembly:
The server receives these segments and reassembles them into the original email.

4. Ensuring Reliability:
If any segment is lost or corrupted during transmission, TCP ensures that it is retransmitted. This process continues until all parts of the email are correctly received.

5. Connection Termination:

  • Once all the email packets are successfully received, the client and server initiate a connection termination process.

  • They exchange messages to ensure the completion of data transfer and agree to close the connection.

  • The four-way handshake concludes the communication.

UDP — User Datagram Protocol

UDP (User Datagram Protocol) is one of the well-known protocols in network communications. Using UDP, we are able to watch video streaming platforms, communicate via video calls, and play numerous games. UDP does not require the source and destination to establish a three-way handshake before transmission takes place. Additionally, there is no need for an end-to-end connection. That's why UDP is sometimes known as the Unreliable Data Protocol.

UDP is simple but fast, at least in comparison to TCP. It's often used for time-sensitive applications (such as real-time video streaming) where speed is more important than accuracy. The primary features of UDP include:

  • Connectionless Communication: No need to establish a connection before sending data.

  • Fast and Lightweight: Data is transmitted quickly with minimal overhead.

  • Unreliable Delivery: There is no guarantee that the data will reach its destination, nor is there any guarantee of delivery order.

  • Datagram Size Limit: UDP has a limit on the size of the data packet that can be transmitted, generally around 65,535 bytes.

Working of User Datagram Protocol (UDP)

In UDP, the data is packaged into smaller units called datagrams and transmitted independently. There is no handshake or setup required, making it faster than TCP. However, since there is no error detection or recovery, data can be lost during transmission or received out of order. This is fine for applications like streaming, where real-time delivery is more critical than perfect reliability.

Example of Using UDP in a Zoom Meeting

Zoom uses UDP (User Datagram Protocol) to facilitate real-time media transmission, such as audio and video, during a meeting. The reason for choosing UDP over TCP for Zoom meetings is UDP's low latency and minimal overhead, which are essential for seamless communication. Here's how UDP is utilized in a Zoom meeting:

1. Media Transmission via UDP: During a Zoom meeting, audio and video data are transmitted using UDP to ensure quick delivery and minimal delay. This approach is crucial to maintain the real-time nature of the communication in a Zoom meeting.

2. Port Usage:

  • Default Ports: Zoom meetings primarily use UDP ports 8801 to 8810 for media transmission. These ports are designated for audio and video streams, ensuring efficient data flow during meetings.

  • Additional Ports: For enhanced performance, Zoom may also use UDP ports in the range of 20000 to 64000.

3. Handling Network Challenges: If a direct UDP connection cannot be established due to network restrictions or firewall settings, Zoom can fall back to using TCP (Transmission Control Protocol) at that time. This ensures that the meeting can proceed even in restrictive network environments.

4. Unreliable Delivery:
In Zoom, if some video frames or audio packets are lost due to network issues, they are not retransmitted. Zoom continues to send new data, minimizing the impact on the meeting. A slight delay or dropped frame does not cause significant problems for the overall conversation.

5. No Reordering of Packets:
Since UDP doesn’t guarantee the order in which the packets are delivered, the Zoom application doesn’t wait for packets to arrive in the correct sequence. It simply displays whatever data it receives, which is usually fast enough that we don’t experience significant disruptions in video and audio.

6. Data Size Limitations:
UDP has a maximum datagram size limit (usually 65,535 bytes), which means large video or audio packets may need to be broken into smaller chunks. However, since Zoom sends relatively small packets and transmits continuously, this limit rarely impacts real-time communication.

By utilizing UDP for media transmission, Zoom ensures that meetings are conducted with minimal latency and high-quality audio and video, providing an optimal experience for users.

Wrapping up!

Thank you for reading! I hope you found this article informative and valuable.

If you have any suggestions or feedback, feel free to share your thoughts in the comments section.

Stay connected with me on: LinkedIn | X