3. **Connection Termination:** The connection is closed gracefully using a four-way handshake **(FIN, ACK, FIN, ACK)**, allowing both parties to end communication without data loss. The termination process typically begins when one side (typically the client) initiates the termination by calling the `close()` system call. As a result the client side kernel send a **FIN** packet to the server. Upon receiving the **FIN**, the server side kernel acknowledges it by sending an **ACK** packet back to the client. At this point, the connection becomes **half-closed**, meaning the client can no longer send data, but the server can still transmit data to the client and the client can receive the data from server. This half-closed state ensures that all the pending data reaches the destination before the connection fully terminates. Once the server completes its data transmission, it must invoke `close()` to intimate the server kernel of its willingness to close the connection. At this point, the server side kernel sends its own **FIN** packet to the client. The client, upon receiving this **FIN**, responds with a final **ACK** packet,and releases the resources associated with the client socket. After receiving the final **ACK**, the resources associated with the server socket gets released.
0 commit comments