TCP Three Way Handshake

tcp three way handshake

 What is TCP three way handshake? 

We know that TCP is one of the implementation example of transport layer protocol according to the OSI model. The protocol is connection oriented, means before sending any data to the remote peer, tcp client setup a virtual connection over packet based underlying IP network.  Three way handshake is the protocol procedure to achieve connection setup. Here we will cover the tcp connection setup procedure in detail.  First question comes in mind, who is responsible for starting TCP connection?  The protocol layer itself ,on startup or some other external entity instruct the layer for connection? The answer is TCP user is responsible to start a TCP three way handshake. For example HTTP (web browser uses HTTP) , is one of the user of TCP. When HTTP user need to send a web request to the remote server. Before sending any user data, HTTP request  TCP to make a connection with the remote server. Once TCP layer receives connection request it starts tcp 3 way handshake. Like any other protocol, the three way handshake procedure requires to exchange packets or messages between client and server.  Following are the  used in connection setup.

Following is message flow for three way handshake.tcp three way handshake

User of HTTP issues a connect request to the TCP layer. TCP layer works as tcp Client and sends the tcp syn with a initial sequence number. Sequence number is to maintain the sequencing of messages. Upon SYN received Sever sends the a new syn and ack of received syn to the client, then client sends the ACK to the server for syn received from server. This completes the connection setup. Following mentions each message in detail for three way handshake.

TCP SYN packet:

This is the first packet from client to the server. TCP message set SYN flag to 1 in message , so make the tcp message as SYN packet. It have the initial sequence number of the client along with other few more parameters.

TCP SYN ACK packet:

After receiving SYN packet, server sends the syn ack packet to the client. Not to mention that this is a single tcp packet with syn and ack bit set to 1. The syn sequence number is the initial sequence number of server accepting the connection.  The ack part have client sequence number plus one. This way server tell that it is ready to accept the packet with next sequence number from the client.

TCP ACK packet:

Final packet for connection setup is tcp ack. Client sends tcp ack packet upon receiving tcp syn ack from server. The packet includes sequence number from server plus one.

TCP user indication after three way handshake : 

In start we have mentioned that , it is the user who initiates connection request. But how the user get,  that connection is done ? And user can use the connection to send data to remote server?  User gets an indication about the connection setup result from the TCP layer.  If handshake is successful, then gets the connection identifier. Else and error.  Connection identifier works as handler for sending/receiving data to/from server. We will show in another post about the exact implementation of TCP client/server , then you can get more clear picture of connection handler.

 

Leave a Comment

Your email address will not be published. Required fields are marked *