TCP Handshakes are to establish or terminate the connection between sender and receiver. You can read more in detail about TCP here. A three-Way handshake is to establish the connection with the server. 4-Way TCP handshake is to finish the connection and to make sure the transmission is successful. Handshakes use flags to communicate with the receiver.
TCP/IP establishes the connection before starting sending the data. Once the data is successful, then it also terminates the connection to avoid using the bandwidth uselessly. To establish the connection TCP uses the “Three-Way Handshake” method. To terminate the connection it uses “4-Way Handshake”. Below is the description of how “TCP Handshakes” works.
TCP is a secure way of sending data. It makes sure that the transmission is successful. In TCP Data transmission it requires an “Acknowledgment” for each packet it sends. Before it starts sending the data first it establishes a connection with the receiver to prevent loss of data.
To establish the connection first it asks the receiver if it wants to receive the data or not? If the receiver is able to receive the data it acknowledges the sender that “Okay I am ready to receive the data”. The sender sends another message to the receiver “Okay the next packet will be the original data”. Since everyone knows that computers cannot communicate in simple words like mentioned above.
The language they speak and understand in this case is “Flags”. You can consider these flags as traffic lights. In Three-Way Handshake “SYN”, “SYN-ACK”, and “ACK” flags are used to communicate between sender and receiver. The sender first sends the “SYN” flag to the receiver which means that the sender wants to send something. if the sender receives back an “SYN-ACK” flag that means that receiver is ready to receive the data. Then the sender sends the “ACK” flag to tell the receiver that the next packet will be the data.
When the sender finishes the data transmission, it terminates the connection with the server using a Four-Way Handshake
4-Way TCP Handshake
4-Way Handshake is the sign that everything went smoothly during the transmission of the data and the data has been reached its destination successfully. A four-Way handshake terminates the connection between sender and receiver so that someone else can use the bandwidth for their data transmission. If the sender does not finish the connection then the receiver will expect other packets from the sender and if does not receive then it may think that some error might have occurred during the transmission.
At the end of the data transmission, the sender sends a “FIN” flag which tells the receiver that I have finished sending the data you may now close the connection. the receiver sends the “ACK” flag which means that “Okay I have received all of your data along with the FIN flag”. the receiver sends “FIN” flag to the sender which means that “Okay then if no data is left let’s close the connection”. The sender sends “ACK” flag to know the receiver that “I have received your FIN flag as well and now I am closing the connection from my side”. When the receiver receives the last “ACK” flag it immediately closes the connection with the sender.
After the Four-Way Handshake, if the sender wants to send other data to the same receiver, it must repeat the process from a 3-Way handshake.
You can read more about flags used in TCP in detail here
3-Way & 4-Way Handshake Diagram
Thank you for visiting our website CSinfos.com! If you have any queries or if you want to talk about anything you can join our community on our Facebook page “Computer Science“. and you can ask whatever is on your mind right now. You can suggest to us any topic that you want us to explain just like this article.