TCP Three Way Handshake

layer4protocol-theorytcptransport-protocol

I have the following query about the tcp handshake.

To establish a connection the server must send a packet with SYN flag to 1
Then the server replies with a SYN,ACK flag to 1 , and afterwards the host (client) replies with ACK flag to 1 and SYN 0.

But to terminate a connection does the host send first termination or the server? Also if its the server is does the server send ACK , FIN to 1 and host replies with ACK 1 and FIN 0?

Best Answer

TCP does not have clients or servers, that is an application concept. TCP creates peer connections. From the application perspective, either the client or the server could request a connection with the other party, depending on how the application is architected. A server application provides a service to a client application. TCP neither knows nor cares which is a server or client.

In such a peering arrangement, either party can request disconnection. That really depends on how the application or service works. Unfortunately, questions about applications and protocols above OSI layer-4 are off-topic here.

For more information about how TCP operates, you can refer to RFC 793, Transmission Control Protocol, and there is Section 2.7. Connection Establishment and Clearing.