TCP Connection Establishment

An application on a host/computer(IP, Port) shall establish TCP connection with other application on another Host/computer(IP, Port) by 3-way handshake. A state is maintained at both end. i.e

(1)Connection initiator sends connection-establishment message to other host (Receiver), 
(2)Now Receiver shall send the acknowledgement of connection-establishment message. 
(3)Now connection initiator shall again send an acknowledgement that it has received the 

All these steps are shown below.

TCP Connection Establishment


Lets see what exactly happens in simplest way of connection putting all complexities such as local policies, retries etc. aside and assuming Host-A acting as CLIENT, Host-B (is in LISTEN state) as SERVER  step by step. 

a) An application on Host-B is up and in Listen state. {Listen} state implies application is ready to accept a TCP connection and waiting for incoming connection requests.

b) Now an Application on Host-A is in Close state, Initiates  a TCP message to establish a connection with Host-B. First message sent by Host-A (Client) is SYN (Synchronize) message. {Close} state means no state.

c) Here in SYN message Host-A shall set a sequence number, this sequence number is unique for given time and random. This sequence number is generated by ISN (Initial Sequence Number generator). SYN-Flag of control flags in header is also set.

d)As soon as SYN message is initialed by Host-A it goes to SYN-SENT state. {SYN-SENT} implies SYN message is sent to Host-B (remote B) and waiting for acknowledgement of SYN i.e. SYN of sequence number 1000.

c)As soon as SYN message is received by Host-B it changes its state from {Listen} to {SYN-RECEIVED} and send the acknowledgement of SYN in SYN-ACK message to Host-A. {SYN-RECEIVED} state implies that SYN received, SYN-ACK send and waiting for acknowledgement of SYN-ACK.

d)SYN-ACK message contains a random,Unique sequence number generated by Host-B, Acknowledgment of SYN by setting acknowledgment section of Header by SEQ-Received +1. I.e. Host-B Expects that next sequence number of incoming   message from Host-A shall be the same as the Acknowledgment Number sent by Host-B. Host-B also sets control flags SYN and ACK, As shown above.

e)Now Host-A receives SYN-ACK check Acknowledgement number, if valid sends ACK and goes in {Established} state otherwise close the connection. {Established} means  open connection, data can be delivered, Data transfer can take place.

f) Host-A sends ACK containing Sequence Number equal to the Acknowledgement number received in SYN-ACK message, sets Acknowledgement field to Sequence Number received in SYN-ACK + 1. ACK control flag is also set.

g)Host-B receives ACK check acknowledgement and sequence numbers if valid goes to {ESTABLISHED} state otherwise close the connection. This how 3-way handshake take place.

h)Once Host-B is in {ESTABLISHED} data transfer from both end can take place as shown above.

Note:-  Once a host goes in established state until connection close request is received. Means of any node reboots/crashes in established state then other node shall not be aware of reboot/crash of remote host because TCP does not have any health check mechanism to check whether established connection is still up or not.

Now we shall move toward some complex situations occurs during TCP connection establishment process. Before we proceed to next topic it would be best we go back to Previous topic TCP Message Format for better understanding coming topics.





Your Comments /Suggestions and Questions are always welcome. We would try to clarify doubts with best of our knowledge. So feel free to put Questions.

No comments:

Post a Comment