Demystifying the Transport Layer
How your Messages Travel Across the Internet
Have you ever wondered what happens behind the scenes when you hit the send button on WhatsApp or any other messaging application? It seems like a simple action – you type a message, click send, and your friend receives it almost instantly. But the journey that message takes through the intricate layers of the internet is anything but simple.
In this blog, we'll delve into the fascinating world of the Transport Layer, a critical component of internet communication, and uncover the magic that enables seamless communication between your device and your friend's.
Let's imagine you are using WhatsApp, a messenger application, to chat with your friend. You write a message, hit send, and your friend receives the message. But what's really going on behind the scenes?
As we discussed before, the Application Layer manages how WhatsApp communicates with the Internet. In the diagram, we can see that a message is being sent from one point to another. This transportation process is taken care of by the Network Layer. It ensures the message travels from one computer to another.
Now, what does the Transport Layer do?
The Transport Layer is like a layer that sits on top of the devices. Its primary job is to handle the information (the message your friend sent) and carry it from the network to the application.
So, while the Network Layer handles delivering the message between computers, the Transport Layer steps in when the message reaches the destination computer. It figures out which application should receive this message (in our case, WhatsApp).
In essence, the Transport Layer provides an abstraction layer. To explain this further, let's consider this analogy: If you and your friend live in different countries and you want to send them a package, you give it to a courier company in your country. That company then passes it to another courier company in your friend's country, which eventually delivers it to your friend. Here, the Network Layer deals with data transfer between devices across different countries, whereas the Transport Layer handles data movement within the same devices.
The Transport Layer takes care of processing data at the application level and then hands it over to the Network Layer for transmission.
So, where do we find the Transport Layer? It resides on our devices or end systems. Within this layer, there are specific protocols we discussed earlier, namely TCP and UDP.
Multiplexing and Demultiplexing:
Let's imagine a situation where we are simultaneously sending a message, a file, and having a video call on our computer. Now, our friend needs to receive all this data on their system. To achieve this, all of this data travels through the internet. But how do our computers know how to send these different types of data to the network, and how does our friend's network determine which application should receive this data? This is where Multiplexing and Demultiplexing come into play.
Multiplexing allows us to combine and send multiple types of data to different destinations using a single medium. The Transport Layer has a multiplexer that handles this task. It takes the various types of data and combines them into packets to be sent over the network. On the receiving end, the Demultiplexer, which is the opposite of the multiplexer, is responsible for sorting out the received packets and directing them to the appropriate applications.
To identify applications on the network, we use port numbers along with IP addresses. IP addresses refer to specific machines, while port numbers are used to distinguish between different applications running on those machines. Additionally, sockets act as gateways between applications and the network, ensuring that applications are properly connected.
When data is sent, the Transport Layer attaches socket port numbers to the packets. These port numbers help the Transport Layer determine which application the data is coming from and to which application it should be sent.
Another essential role of the Transport Layer is congestion control, which manages traffic flow. Congestion occurs when there is a high volume of data trying to pass through limited network resources. TCP (Transmission Control Protocol) uses various algorithms for congestion control to ensure that data is transmitted efficiently and without overwhelming the network.
Checksum:
Imagine you are sending an important message to your friend over the Internet. The message travels through different networks and routers before reaching your friend's device. However, during this journey, there's a chance that some errors might occur. These errors could be caused by noisy communication channels or technical glitches along the way. This is where checksums come into play as there would be no way to verify if the message arrived intact and unchanged at your friend's end. It's like sending a letter in the mail without a return address or any confirmation that it reached the right destination without any damage or alterations.
The checksum in the Transport Layer acts like a safety seal on the message. Before the message is sent, the Transport Layer calculates a unique code (the checksum) based on the content of the message. This code is sent along with the message. When the message reaches your friend's device, the Transport Layer recalculates the checksum based on the received message content.
If the calculated checksum on your friend's end matches the one sent with the message, it means the message arrived without any errors or changes. It's like receiving a sealed envelope with a matching stamp, assuring that nothing has been tampered with during transit.
However, if the checksum doesn't match, it signals that something went wrong during the journey. It could be due to a bit flip, data corruption, or other issues. In this case, the Transport Layer knows that the message might be compromised and takes measures to request the retransmission of the message to ensure your friend receives the correct and complete message.
Timers:
Imagine you're using a messaging application to send a message to your friend over the internet. The message is divided into small packets for transmission. When you send packet 1, a timer starts to measure the time. This allows you to know when your friend receives packet 1, as the timer ends. Now, suppose you send another packet, let's call it packet 2. Due to network congestion or other issues, packet 2 gets lost in transit, and your friend's device never receives it. So, you start the timer again, hoping to receive it back. However, since your friend never receives packet 2, the timer expires, indicating that this packet was not successfully sent. This timer mechanism is called a retransmission timer.
Now, let's consider that you're sending something, like packet 1, to your friend. As you send it, the timer starts, and when your friend receives packet 1, the timer ends. Later, you send another packet, let's call it packet 2, and start the timer again. This time, your friend sends a response, but unfortunately, you don't receive anything from them, and the timer expires. In this situation, you can't be certain whether your friend received packet 2 or not.
To address this issue, we use sequence numbers. Each packet is assigned a unique identification number, which acts as a sequence number. With this, we can determine if we have already received a specific segment, like segment 2. If it's already present, then we know that it's a duplicate, and we can handle it accordingly. Now let's explore the Transport layer protocols:
UDP - User Datagram Protocol
UDP is a transport layer protocol. It may or may not deliver data, and the data may change or not be in order. It operates as a connectionless protocol, meaning no formal connection is established between two computers for data transmission. Despite this, UDP employs checksums to determine if the data is corrupted, yet it doesn't take any corrective action. So, the question arises, why do we use it?
Use cases for UDP include:
It offers high speed.
Video conferencing.
DNS communication (UDP is used for DNS queries).
Gaming (where real-time data transmission is crucial).
To observe the data packets being sent and received by your computer, you can use the following command:
bash sudo tcpdump -c 5
This command will display the details of five packets that have been captured, showing whether they were received or dropped.
The structure of a UDP packet is like a simple envelope that contains information for sending data over the internet. It has two important parts:
Header: This is like the address on the envelope. It contains important details about the packet, such as the source port number (where the data is coming from), the destination port number (where the data is going to), the length of the packet, and a checksum for error detection.
Data: This is the actual message or information that needs to be sent. It's like the letter inside the envelope. It can be anything from a small piece of text to a video or audio file.
TCP - Transmission Control Protocol
TCP, which stands for Transmission Control Protocol, is a Transport layer protocol used in computer networks.
In the Application layer, a significant amount of raw data is sent, and TCP segments this data by dividing it into smaller chunks, adding headers, checksums, and other necessary information.
For instance, if you have some data in the Transport layer that needs to be passed to the Network layer, the Network layer might further divide this data into even smaller chunks. When your friend receives these smaller chunks, they will be reassembled back into the original data.
TCP also provides congestion control, as discussed earlier.
It handles two important tasks:
Ensuring data arrives correctly.
Maintaining the order of data. Some use cases of TCP include:
Features:
It is connection-oriented, meaning a connection must be established before data can be sent.
TCP provides error control to ensure data integrity.
It also includes congestion control mechanisms.
TCP operates in a bidirectional full-duplex manner. This means that two computers connected to each other, such as computer A and computer B, can send files to each other simultaneously, as shown in the figure below:
It's important to note that using TCP, there can only be two endpoints like this, and you cannot send one message to multiple devices. Each device will have its own TCP connection, resulting in one TCP connection between two computers.
Now, let's explore how the connection establishment in TCP happens:
3-Way Handshake:
The 3-Way Handshake is a process used to establish a TCP connection between a client and a server. Let's explain the steps involved in the 3-Way Handshake and correct the lines with appropriate syntax and accurate data:
Step 1: Client sends a connection request to the server. In this request, the client includes a synchronization flag (SYN) in the header, indicating that a new connection is being initiated. Additionally, the client assigns a random sequence number, let's say 32, to help keep track of the data packets.
Step 2: The server receives the client's request and responds with its own synchronization flag (SYN) to indicate that it acknowledges the client's request and is also initiating a new connection. The server also includes an acknowledgment flag (ACK) and generates its own sequence number, let's say 56, by performing some calculations based on the client's sequence number.
Step 3: The client receives the server's response. It acknowledges the server's SYN flag and acknowledges receipt of the server's sequence number (56) by sending an ACK flag back to the server.
At this point, the 3-Way Handshake is complete, and the TCP connection between the client and the server is established. Now both parties can start exchanging data with confidence that the connection has been successfully established.
Conclusion
The Transport Layer is like a silent hero in our online activities. It quietly makes sure that the information we send and receive over the internet is safe and accurate. It does this by organizing our data, checking for errors, and keeping everything in order.
So, the next time you send a message on WhatsApp or engage in any online activity, remember the Transport Layer quietly doing its job to keep your data flowing smoothly across the vast expanse of the internet.
Thank you for reading the blog. Check out the complete Computer Networking Series.
Feel free to connect with me on: