Imagine whispering a message to your friend across a noisy room or surrounding area and then your friend repeats it back to you to ensure he/she heard it correctly. This simple act of confirmation by your friend ensures that you successfully deliver to your friend, not any other person. Think of it as what happens in the digital world or internet networks through the TCP 3 - way handshake. It ensures smooth, secure and reliable communication between devices or servers without it your messages and data could be lost in the vast world of internet. But don’t worry in this article you will get to know how TCP 3 - way handshakes work and why its so important for communication over the internet.
But before jumping into TCP 3 - way handshake you would have to know some basic of what is TCP/IP so here is the link where you may get the basic knowledge to understand the TCP 3 - way handshake, why its important, etc in upcoming sections.
What Is the TCP 3 - Way Handshake ?
The TCP 3 - way handshake is a step by step process used to create a reliable connection between two devices or devices to a server like your computer, phone, etc and the web server. It ensures that both devices are ready to talk to each other before any actual data is shared or sent. Lets discuss each of three steps -
1 → SYN (Synchronize) - The client (like your computer or phone) sends a SYN message to the server and ask to start the conversation. Think of it as the client asking from the server - "Hi can we talk ?” or think as like sending a your friend a message which says - “Hi are you free to chat” now here you checking if your friend is available or not. Also this initial message includes a sequence number which acts like a unique identifier for the conversation. Its the first step to establishing the communication with the server.
2 → SYN - ACK (Synchronize - Acknowledge) - The server replies with a SYN - ACK message saying - “Yes i’m here and ready to talk. Can you confirm ?”. Imagine your friend responding - “Yes i’m online and ready to chat”. This message not only acknowledges the client request but also sends its own sequence number for creating a two way connection.
3 → ACK (Acknowledge) - The client sends and ACK message back to the server which confirming “Okay lets start”. Think as you reply to your friend - “Great lets start the conversations or chatting”. This final step ensures both parties (client and server) have received and acknowledged the necessary information to begin the communication reliably, smoothly and securely.
Why is the TCP 3-Way Handshake Important ?
The TCP 3 - way handshake is important because of (discuss point wise below) -
→ Ensure both devices or devices and servers are ready to communicate. It checks that the server is online and ready to communicate. Its like ensuring both you and your friend have time to talk before starting the conversation.
→ Organizes the conversations between the devices and the servers. It set up sequence number (remember the sequence number which also send while 3- way handshake) to make sure all the data arrives in the correct order. Think of this as arranging the data in the correct order so that neither the device nor the server gets the data in the wrong correct order. The sequence numbers ensure that even if data packets arrive out of order can rearrange the data in the correct order.
→ Makes communication reliable, smooth and secure. It helps prevent data from getting lost or corrupted during transmission. This is like making sure your friend repeats the bro code back to you correctly before moving on. Each step ensures that both devices are synchronized and ready for error free communication which is reliable.
Without these process devices might try to send data without knowing if the other side (server) is ready which leads to errors, loss and lost of data, miscommunication, etc.
Now i know you wonder how sequence numbers and ACKs work behind the scenes. So lets discuss about in the next section.
Reliable Connections in TCP - How Sequence Numbers and ACKs Work
TCP ensures reliable communication by using sequence numbers and acknowledgement (ACK) message to track data packets and ensures their delivery. Lets see how it works -
1 → Sequence Numbers - Each byte of data sent over a TCP connection is assigned a unique sequence number. This allows the receiving device to arrange the data in the correct order even if data packets arrive out of sequence or order. The initial sequence number is chosen randomly during the handshake process to enhance security reasons and prevent certain types of attacks. Imagine sending a set of comicbooks for a particular story (10 volumes) to your friend and if the set of comicbooks is shuffled during delivery your friend see the volume number of the cover page which helps him/her to rearrange them in the correct order.
2 → Acknowledgement Number - When a device receives data it sends an ACK (acknowledgement) message back to confirm the communication. The ACK includes the sequence number of the next byte it expects to receive. This confirmation ensures that the sender knows the data has arrived safely and can retransmit any missing data packets. Think as your friend receives a set of comicbooks but only gets 5 out of 10 volumes and says to you, got the 5 send the other 5 also.
3 → Retransmission - If the sender doesn’t receive an ACK within a certain time period then it assumes the packet was lost on the way and retransmit it. This mechanism minimizes the impact of network issues and ensure that no data is lost. Think is like your friend replies to you - my friend i get all the comicbooks or not then you send it again to your friend.
Analogy for TCP 3 - Way Handshake
Imagine you are texting a friend on a messaging app -
1 → You (the client) send a message to your friend - “Hi, are you online ?” This is like the SYN message. You are initiating the conversation and waiting for a response.
2 → Your friend (the server) reply - “Yes I’m here are you online and ready to chat” This is like the SYN-ACK message. Your friend is confirming he/she received your message and checking if you are ready to continue conversation.
3 → You (the client) reply - “Yes I’m online Lets chat” This is the ACK message. You have now confirmed his/her response and you and your friend are now both ready to start the chatting or conversation.
Conclusion
The TCP 3-way handshake is a important part of how the internet works. It ensures that devices communicate smoothly, securely and reliably. By understanding this handshake now you know why TCP use 3 - way handshake and why it is important for communication between devices and the servers over the network.
Thanks for reading this far.