The destination receives the packet with the SYN (0x02) lag and sends an
acknowledgement to the source by setting the ACK (0x10) lag in the reply.
This stage is called SYN-ACK.
The source receives the SYN-ACK message and sends an ACK segment,
which notes that each packet in the TCP messages contains a sequence
number to maintain the order.
Once the transmission is done, the FIN (0x01) lag is set in the next
SYN=M, SEQ #N
SYN = M, ACK = M, ACK #N
ACK = M, SEQ #N
The three-way handshake protocol
The sequence numbers allow TCP to control the low. TCP uses a sliding-window
technique. If an ACK segment is not received in a particular period of time, then it
retransmits the missing part of data. However, choosing an appropriate timeout is not
an easy task. Therefore, in order to solve this issue, TCP uses adaptive retransmission.