Understanding TCP 3-Way Handshake
Decoding How The Client-Server Connection Initiates
Hello Learners!
Ever wondered how the browser (client) & server ensure that the connection over which they are communicating is reliable? Is the connection sufficient enough to carry on the communication?
If yes, then you have come to the right place. This article will decode the TCP 3-Way Handshake mechanism through which client (browser, for example) & server establish a reliable connection for further communications! This article will not be just mere text & will have diagrams, images and easier explanations to understand the mechanism! So let’s dive into it!
TCP → Transmission Control Protocol
Before diving into 3-Way Handshake, let’s make our foundations strong and understand TCP in a minute.
It is a mechanism through which Computers send data over the internet (network). But why is it important? It is important because it is immensely reliable and makes sure that there are no packet losses.
Wait…. Packets?! → Yes, the data across the internet is shared in small chunks of packets and not completely in one-go.
Analogy → You wanted to order an outfit from amazon. Instead of ordering the whole outfit at once, you ordered T-shirt, jacket, jean, shoes and the order came in different individual packets (data divided into packets )
TCP ensure that →
There are no packets losses, as described above
Analogy → You ordered an outfit (T-shirt, jacket, jean, shoes) from amazon right? Would you want to receive only jacket and jean and nothing else? It would result in packet loss!
Packets are sent and received in the correct sequence (check the numbering in the above diagram). The sequence becomes really important when communicating.
Analogy → Your friend texted you ohell instead of hello, is it the right way to say hello??!
It has the capability to resend the lost data in case of any errors.
Analogy → Your friend texted you ohell but later edited the message and sent you hello.
Basically, TCP is a set of rules that governs how will the transmission of data take place between client & server.
3-Way Handshake
It’s time to dive into the main focus here which is the 3-way handshake. Let’s understand it with the help of an analogy.
Analogy → Your friend wanted to play table tennis but he could not play alone. He told you “I want to play table tennis“ You replied “I also want to play table tennis & I have got your request” Your friend replied “I have received your approval! Let’s play”. Then you played for 5 hours continuously & seamlessly without any break.
There were 3 steps involved in the above example →
Your friend said → I want to play table tennis
You replied → I also want to play, I have got your request.
Your friend replied → I got your approval. Let us play
Similarly, there are 3 steps in 3-Way Handshake →
SYN (synchronise)
Client is telling the server that I want to make a reliable connection with you. So, let’s synchronise.
Synchronise just means → Let’s make a reliable connection
Similar to how your friend told you he wants to play table tennis.
This message also contains an initial sequence number which tells the server about the point where the data sending is to start from. Remember the sequencing of packets in above diagram?
SYN - ACK (Synchronise - Acknowledge)
Server is telling the client that I also want to connect with you & I have received your request to connect.
Acknowledge just means → Yeah, I received your request
Similar to how you told your friend that you also want to play table tennis & you have received his request.
It boils down to this essentially →
Different arrows of SYN & ACK clubbed together to form SYN - ACK
It also contains a sequence number which establishes an accepted common initial point of data sending.
ACK (Acknowledge)
Client is telling the server that it has got his approval to connect → Let us establish a reliable connection for further communication.
Similar to how your friend finally told you that he has received your approval & you started playing without any interruption.
What happens after the 3-Way Handshake?
After the 3-Way Handshake the client & the server start sharing the actual data. Here is a breakdown of what happens after the 3-Way Handshake →
Both sides start to share data packets with each other. These packets will have sequence numbers as well that they initially agreed upon.
If there is a packet loss or any error then TCP can request to re-transmit the data packet.
Client & Server will maintain the connection and data packets will keep on flowing until client or server decides to close the connection.
Conclusion
We just saw in this article how beneficial and useful the 3-Way Handshake is. It provides everything for a seamless connection establishment → Reliable connection maintenance, Correct order of data packet sending, Checking on the packet received & error resolving as well.
I hope you loved the article and I am pretty confident that by now you would have understood the topic of the article ‘3-Way Handshake’ .
Follow my blog as I will be writing more articles decoding topics like these which appear complex on the face but are easier to understand when explained easily.