There is a procedure of 3-way handshake which is for the purpose of establishment of connection in case of TCP , now in that procedure, the different parameters are exchanged b/w server and client and the random initial sequence number is also communicated.[If the SYN
flag is set (1), then this is the initial sequence number. The sequence number of the actual first data byte and the acknowledged number in the corresponding ACK are then this sequence number plus 1.]
Protocols operations :
LISTEN
(server) represents waiting for a connection request from any remote TCP and port.
SYN-SENT
(client) represents waiting for a matching connection request after having sent a connection request.
SYN-RECEIVED
(server) represents waiting for a confirming connection request acknowledgment after having both received and sent a connection request.
ESTABLISHED
(both server and client) represents an open connection, data received can be delivered to the user. The normal state for the data transfer phase of the connection.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Now after completion of sending the segment the Tcp invokes another segment which is for the closing of connection.FIN
(1 bit) is set to 1 which indicates last bit from sender.
FIN-WAIT-1
(both server and client) represents waiting for a connection termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent.
FIN-WAIT-2
(both server and client) represents waiting for a connection termination request from the remote TCP.
CLOSE-WAIT
(both server and client) represents waiting for a connection termination request from the local user.
CLOSING
(both server and client) represents waiting for a connection termination request acknowledgment from the remote TCP.
LAST-ACK
(both server and client) represents waiting for an acknowledgment of the connection termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request).
TIME-WAIT
(either server or client) represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request.
CLOSED
(both server and client) represents no connection state at all.
Reference :https://en.wikipedia.org/wiki/Transmission_Control_Protocol