It takes 3 segments minimum to establish a connection and 4 segments to terminate a connection.
TCP Connection Termination
- One side, either client or server, calls close, and goes into active close and sends a FIN segment to the other side.
- After receiving FIN, the other side goes into passive close. Reception of FIN is also acknowledged by TCP, after any data that may already have been queued, like an EOF (by the one in active close).
- After some time, the side that receives the EOF will close its socket, and TCP sends another FIN.
- The other side acknowledges the final FIN.
Packets exchanged when TCP connection is closed
A FIN occupies one byte of sequence number space just like SYN. Acknowledgement of each FIN is the sequence number of FIN + 1.
During the connection termination process, there may be some final data flow from the end that did not call close first, from the one who went in passive close to the one who went in active close. This situation is called half-close.
Saturday 24 September 2016