3 way- handshake protocol
3 way- handshake protocol
3 way- handshake protocol
The process of communication between devices over the internet happens according to the
current TCP/IP suite model(stripped-out version of OSI reference model).
The Application layer is a top pile of a stack of TCP/IP models from where network-referenced
applications like web browsers on the client side establish a connection with the server.
From the application layer, the information is transferred to the transport layer where our topic
comes into the picture.
The two important protocols of this layer are – TCP, and UDP(User Datagram Protocol) out of which
TCP is prevalent(since it provides reliability for the connection established).
However, you can find an application of UDP in querying the DNS server to get the binary equivalent
of the Domain Name used for the website.
TCP establishes a secure and reliable connection between two devices. This is possible because of
the TCP’s 3-way handshake process, which occurs when two devices establish and close connections.
There are three steps to both establishing and closing the connection, as the name implies. So, in this
article, we’ll go through the TCP 3-way handshake process and the various steps that it includes.
TCP provides reliable communication with something called Positive Acknowledgement with Re-
transmission(PAR) . The Protocol Data Unit(PDU) of the transport layer is called a segment. Now a
device using PAR resend the data unit until it receives an acknowledgement. If the data unit received
at the receiver’s end is damaged(It checks the data with checksum functionality of the transport
layer that is used for Error Detection ), the receiver discards the segment. So the sender has to
resend the data unit for which positive acknowledgement is not received. You can realize from the
above mechanism that three segments are exchanged between sender(client) and receiver(server)
for a reliable TCP connection to get established. Let us delve into how this mechanism works
Step 1 (SYN): In the first step, the client wants to establish a connection with a server, so it
sends a segment with SYN(Synchronize Sequence Number) which informs the server that the
client is likely to start communication and with what sequence number it starts segments
with
Step 2 (SYN + ACK): Server responds to the client request with SYN-ACK signal bits set.
Acknowledgement(ACK) signifies the response of the segment it received and SYN signifies
with what sequence number it is likely to start the segments with
Step 3 (ACK): In the final part client acknowledges the response of the server and they both
establish a reliable connection with which they will start the actual data transfe
The three steps involved in establishing a connection using the 3-way handshake process in TCP are
as follows:
1. The client sends the SYN (synchronize) message to the server: When a client requests to
connect to a server, it sends the message to the server with the SYN flag set to 1. The
message also includes:
The maximum segment size. For example, if the window size is 3000 bits and the
maximum segment size is 300 bits, the connection can send a maximum of 10 data
segments (3000/300 = 10).
2. The server responds with the SYN and the ACK (synchronize-acknowledge) message to the
client: After receiving the synchronization request, the server sends the client an
acknowledgment by changing the ACK flag to ‘1’. The ACK’s acknowledgment number is one
higher than the sequence number received. If the client sends an SYN with a sequence
number of 2000, the server will send the ACK using acknowledgment number = 20001. If the
server wants to create the connection, it sets the SYN flag to ‘1’ and transmits it to the client.
The SYN sequence number used here will be different from the SYN used by the client. The
server also informs the client of its window size and maximum segment size. After this step is
completed, the connection is established from the client to the server.
3. The client sends the ACK (acknowledge) message to the server: The client will set
the ACK flag to ‘1’ after receiving the SYN from the server and transmits it with an
acknowledgment number 1 greater than the server’s SYN sequence number. The SYN flag
has been set to ‘0’ in this case. The connection between the server and the client is now
formed after this phase is completed.
Most implementations today allow three-way and four-way handshaking with a half-close option for
connection termination. Here we only mentioned the steps of three-way handshaking for connection
termination. The three steps involved in terminating a connection using the 3-way handshake
process in TCP are as follows:
1. The client sends the FIN (finish) message to the server: When the client decides to
disconnect from the network, it transmits the message to the server with a random
sequence number and sets the FIN flag to ‘1’. ACK is set to 0 in this case.
2. The server responds with the FIN and the ACK (finish-acknowledge) message to the client:
After receiving the request, the server acknowledges the client’s termination request by
changing the ACK flag to ‘1’. The ACK’s acknowledgment number is one higher than the
sequence number received. If the client sends a FIN with a sequence number of 2000, the
server will send the ACK using acknowledgment number = 20001. If the server also decides
to terminate the connection, it sets the FIN flag to ‘1’ and transmits it to the client.
The FIN sequence number used here will be different from the FIN used by the client. After
this step is completed, the connection between the client to the server is disconnected.
3. The client sends the ACK (acknowledge) message to the server: The client will set
the ACK flag to ‘1’ after receiving the FIN from the server and transmits it with an
acknowledgment number 1 greater than the server’s FIN sequence number. The FIN flag is
set to ‘0’ in this case. After this step is completed, the connection is also disconnected from
the server to the client.