Beyond the Magic Doors

Beyond the Magic Doors

Navigating the Digital Symphony of Ports and TCP

In the previous blog where we explored ports, we learned that ports and addresses alone are not sufficient for effective communication between computers. Successful data transfer between two parties also involves specific mantras(protocols) that both the client and server must follow to ensure a seamless connection. In this upcoming blog, we will delve into the precise processes undertaken by both the client and server, uncovering the essential steps required for a successful exchange of data between these digital entities.

Are Ports and Addresses Enough?

Recalling our previous journey through computer communication, we discovered that for effective data exchange between a client and a server, the client requires both a magic door number (ports) and an address(IP). However, it's important to note that the process isn't as straightforward as simply having an address. Before any data transfer can occur, a crucial step must take place: the client and server must establish a magical bridge connecting them.

Once you reached the door!

After the client finds the server with the help of the address, the client and server first try to set the bridge between them with the help of the TCP layer of the system where some mantras will be exchanged between them for successful connection.

What is TCP?

Transmission Control Protocol (TCP) is a connection-oriented protocol that is used to ensure the reliable delivery of data over a network.

TCP works by breaking down data into small segments, called packets. Each packet is assigned a sequence number, which is used to ensure that the packets are delivered in the correct order

Let us understand this with an example

Think like one party(client) need some amount of people to do their work so, the client requests the other party(server) who has many people who can do the work

but here is a cache if the people need to be transferred from one place to another there should be a way that should exist right?

So to create a temporary way some initial conversations are happening between both parties to build a bridge

So at first on behalf of the client, one person is sent to the server from the control department(TCP layer) of the client and the control department(TCP layer) of the server accepts the request and replies and asks for reconfirmation Then the temporary bridge is created.

But the bridge is built in a way that it has many paths that are used to go from one(server) place to another(client) and each path can accommodate only a certain amount of people(data). So, the control department(TCP layer) of the server splits the total people(the response: in the case of the website the whole html page) into subgroups(packets) and these subgroups(packets) are also numbered sequentially, which reach the other end of the bridge client in an unordered manner, the control department(TCP layer) of the client will take care of ordering the subgroups sequentially and will be utilized by the client.

But how does the client know that all groups (packets) have reached them?

Each group have been assigned a timer(Maximum Segment Lifetime(MSL)) which is the maximum time taken by them (packets) to reach the client, If it is not reached then the group is said to be lost in the way
Like this, the two parties are transferring data between them

It is time to understand how in real-world two machines communicate

The Client and the Server

The first three steps that will happen when the client reaches the server are as follows,

  1. The TCP layer of the client initiates the communication by sending a SYN packet to the TCP layer of the server. This packet contains the client's initial sequence number, which is a number that the client will use to number the segments that it sends

  2. The server responds with a SYN-ACK packet, which contains the server's initial sequence number and an acknowledgement of the client's sequence number. This packet also tells the client that the server is willing to accept the connection.

  3. The client then sends an ACK packet to the server, which acknowledges the server's sequence number.

The client and server engage in a series of steps to kickstart communication, known as the three-way handshake.

Once the three-way handshake is completed, data is then transferred between the client and server in a bidirectional manner, following the established protocol.

Once the connection is established the data are transferred between the client and server.

Once the data transfer is complete, and both the client and server have no more data to send or receive, either the client or the server can initiate the termination of the TCP connection. The following states occur during the termination process

Assuming the termination is started by the client

The client sends the FIN packet typically referred as the Finish packet which says the client wants to close the connection.

The client enters the FIN_WAIT_1 state, waiting for an acknowledgement from the server to confirm the termination.

The server enters CLOSE_WAIT, acknowledging the client's request with ACK

On receiving the ACK from the server, the client enters FIN_WAIT_2 and the client waits for the FIN from the server and the server moves to LAST_ACK, on receiving the FIN, the client acknowledges it by sending back the ACK to the server and the client enters the TIME_WAIT and on receiving the ACK from the client the server moved to the CLOSED state

Now on receiving the ACK the server side is closed for data transmission means the one side of the bridge is closed.

On the client side, after entering the TIME_WAIT state, the connection doesn't immediately close in the next instance. Instead, it remains in the TIME_WAIT state for a specific duration, which is typically twice the Maximum Segment Lifetime (MSL). After this waiting period, the connection eventually closes.

This is to ensure that any packets are left remaining to be received.

After this waiting period, the connection eventually closes, the resources are released by the client and both the client and server are completely moved to the closed state and the bridge is destroyed.

Conclusion

In conclusion, the three-way handshake serves as the cornerstone of reliable data communication, ensuring a secure bridge for seamless exchanges. But what if we could make this bridge indestructible? Join us in our next blog as we explore ways to strengthen this vital connection. Until then, remember the importance of clear communication in the world of networking.