Network Basics: TCP Session Establishment - Handshaking
To send data over TCP in a network, you should follow the required session establishment process, known as handshaking, or more specifically, a three-way handshake because it involves completing three IP packets. The three-way handshake is illustrated in the following figure and involves these three frames.
SYN: This is the synchronization phase. This TCP segment sets the sequence number to be used for the upcoming data transfer.
SYN-ACK: The reply from the remote host does two things:
Verifies the sequence number that will be used.
Acknowledges the original request.
ACK: This data is sent from the originating host, and acknowledges the sequence number and the acknowledgement from the targeted host.
After being established through the handshaking process, the TCP sequence numbers will be used in sequential order until the session is terminated. The sequence numbers allow all the data to arrive in order (or in the correct sequence).
There is a process to start a session, and there is also a process to terminate the TCP session. To terminate the session, a Finish frame is sent from one host to the other:
FIN: The Finish frame is a request that the session be terminated.
FIN-ACK: The response to a finish request is an agreement for finishing and an acknowledgement. Unlike session setup, there is no follow-up acknowledgement; this end of the session is closed when the data is sent. The remote host closes its end of the connection when it receives FIN-ACK.