Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
In this article, we will discover how a connection between client and server happens using 3-way handshake.A 3-way handshake is a fundamental process in the Transmission of Control Protocol/Internet Protocol (TCP/IP). It has been used by internet devices to have a secure and reliable connection.
What Is TCP?
TCP is an internet protocol that is responsible for sending a packet over the internet in a secure and reliable way,
It does so by breaking down the data to be sent into packets and transmitting them over the internet, and reassembling them on the receiving side of the internet.
3 Way Handshake Connection Process
3 way handshake is an essential operation in TCP/IP networking. In order to establish a connection, the client first sends a SYN packet to the server. The SYN-ACK response from the server signifies its readiness. The connection is formed after the client sends an ACK, enabling data transfer between them.
Let's take a look at the steps involved in the 3 way handshake process.
The three major steps are:
1.SYN(Synchronisation Sequence Number) from Client to Server
2. SYN+ACK(Acknowledgement) from the server to the client
3. ACK client to the server
SYN From Client to Server
First, the client sends a packet with only the sequence number and SYN flag bit(flag bit is set to 1) and (ACK flag bit is set to 0) to the server in its header tag. The server also must have open ports that can set up and accept new connections.
The purpose is also to check if the server is open for new connections.
This initial packet allows the client to set the first sequence number for the rest of the request packets coming from the client.
This packet contains a random sequence number generated by the client, which is used for further identification that the packet originated from this specific client and sets a new communication session.
The sequence bit is typically 32-bit.
Its purpose is to ensure that all the remaining data packets arrive in their correct order.
Syn + ACK From Server To Client
Upon receiving the SYN request from the client, the server sets the ACK flag bit to 1.
Then the server sends an SYN+ACK packet with an ACK flag bit set to 1, which acknowledges the receipt of the server's SYN packet.
The ACK represents the response of the segment received, and the SYN represents the sequence number with which the rest of the data packets will start.
While sending the SYN-ACK packet, the server sets the ACK to syn+1 of the SYN packet. For example, if the sequence number is 2905, it will send 2906.
The server also generates its sequence number to identify the session and advertises its window size and maximum segment size. For example, if the data packet is 100 and the maximum segment size is 10, then ten packets must be sent.
ACK Client To Server
Now that the client receives an SYN+ACK packet, it responds with an ACK packet to the server by acknowledging the arrival of the SYN+ACK packet.
This packet contains an acknowledgement number set to the sequence number of the SYN-ACK packet plus one.
After sending the ACK packet to the server, a secure connection is set up, and data transfer can begin.
Note: The above diagram Illustrates complete 3-way handshake process. The 3-way handshake is a critical process in establishing a reliable and secure connection between two devices over a network. It involves a series of steps where both devices exchange information and acknowledge each other's readiness to communicate.
3-Way Handshake Closing Connection Process
Following given are the steps for 3-way handshake for closing a TCP connection:
The sender starts the closure, by sending a FIN (Finish) packet to the recipient.
The receiver sends an ACK (Acknowledgment) packet in response to the FIN.
The receiver then transmits a FIN packet of its own to confirm that it is okay to terminate the connection.
The sender sends an ACK in response to the receiver's FIN.
The connection has been completely cut off.
Frequently Asked Questions
What happens if one of the 3-way handshake packets is delayed?
If even one of the packets is lost during the transmission, the connection has to be established, and the process has to start from the beginning again.
How does a 3-way handshake ensure that both parties are in sync?
The three-way handshake maintains synchronization by exchanging numbers in SYN and SYN-ACK packets, which is used to confirm the initial sequence number for the remaining data packets. In response to the server's SYN-ACK, the client's ACK packet assures synchronization.
What happens after a TCP 3-way handshake?
Data can move back and forth between the client and server once a TCP 3-way handshake creates a connection. Data packets are exchanged, acknowledged upon reception, and conversation is then continued. A four-way handshake completes the connection and releases the associated resources.
What is a 3-way and 4 way handshake?
A TCP connection is established using a 3-way handshake in which the client sends a SYN, the server answers with a SYN-ACK, and the client acknowledges with an ACK. A TCP connection is gracefully closed using a 4-way handshake that involves the exchange of FIN and ACK packets by both sides.
Why is a 3-way handshake required in the TCP/IP protocol?
The TCP/IP protocol requires a 3-way handshake to guarantee a safe and reliable connection initiation process between a client and server before actual data exchange can start.
Conclusion
In conclusion, the 3-way handshake process ensures that the client and server are aware of the connection and agree to communicate with each other. The overall process is as follows:
The client sends a SYN packet.
The server sends an SYN-ACK packet.
The client acknowledges the server with an SYN-ACK packet.
This procedure is carried out for each communication session to ensure the client and server are connected, synchronized, and ready to communicate and share data.
To learn more about networking, check out our articles: