TCP Working: 3-Way Handshake & Reliable Communication
Why do we need to need a handshake?

Even though there is a firewall at the router level, the network can be compromised at any level. So every layer of communication needs its own reliability and integrity, so that one does not infiltrate the other borderlines and get the data and execute any action they want to perform.
As mentioned in the TCP vs udp article https://blog.yogeshkumar.site/tcp-vs-udp, TCP is reliable, not only because of the retransmission in the transport, but also because there is reliability and integrity that is required when communicating with the server to which the data is requested.
But how does the secure connection happen? will be explored in this article.
As we already know, the internet is a network of networks, so to ensure the data is sent to be received by the correct server or client, it has to be ensured that once we find that this is the system we want to communicate with, and whether it is willing to communicate with the client.
Once I know (I mean, my browser knows) that my blog is hosted on Hashnode. network through DNS lookup, and the GET request to the server is sent, and before that, the connection between the os and server has to be available and secured to the browser (client).
This happens in a series of exchanges of messages called SYN→SYN-ACK→ACK exchange of data packets called the three-way handshake, for the availability of the connection, the integrity of the connection, and for the communication.

Initial Sequence Numbers (ISN) are used to track every byte of data sent over TCP. Similarly, the server sends the Acknowledgement Number in the packet as well.

Client sends a Synchronised (SYN) request, called a SYN packet, to the server to check the availability of the port for communication and access to the server.
The server sends back the acceptance message, called a SYN-ACK (Acknowledgement) packet, back to the client that yes i am available and willing to communicate, and your access has been justified.
The client then sends the acknowledgement ACK packet that I have received your SYN-ACK packet for confirmation.
This is the ideal case scenario where this happens when everything is fine; otherwise, it can be interrupted at any point and closed.
What is the packet that the client and server sends among each other? The sequence of randomly generated numbers is used to track the data sent and received in the connection for verification and reliability of the connection.
Sequence Numbers (Seq) are used to track every byte of data sent over TCP. Similarly, the server sends the Acknowledgement Number in the packet as well.

But how do these numbers make it reliable?
If the client sends the data and does not receive the acknowledgement, it resends the data, which means upon loss, the data is retransmitted.

If there is a loss of order during transmission, the server receives them in the wrong order and tries to re-order them using sequence numbers itself, and while it does that, it buffers.

When there is corruption of data in the middle and reciever recieves the corrupted data, there is a verification using the sequence numbers called checksum verification that triggers the retransmission.

Thus making it reliable.
If it is that reliable, it should be closed with grace as well; the connection remains open forever.
The application triggers the closure of the TCP socket connection by sending a FIN packet, and the server acknowledges that by sending the ACK packet. Then the server sends the FIN, ACK packet, and atlast the client sends the ACK packet for the acknowledgement of the closure.

I tried to simplify as much as possible, but I believe the closure needs an article of its own. I will link to the article I have researched and understood. See you on the internet!!!



