Master TCP Connection Establishment and Termination – Boost Your Skills (Updated 2025)

A diagram comparing TCP connection establishment and termination between a Host and a Server. The left side shows the three-step process: Host sending SYN, Server sending SYN ACK, and Host sending ACK to establish the connection. The right side shows the four-step termination: Host sending FIN, Server sending ACK and FIN, and Host sending ACK to terminate.

All application processes on the server use unique port numbers. The network administrator can use default ports (e.g., 80 for HTTP, 21 for FTP) or configure custom ports manually, ensuring no conflicts. An active server application requiring an open port on the server means the transport layer accepts and processes segments addressed to that port number. Every client’s incoming request is accepted at the correct socket address, and the application passes the data to the server. So, there are possibilities for open ports simultaneously on the same server, one for each active server application.

TCP Connection Establishment

When two people get together, they often welcome each other by shaking hands. Establishing a connection in networking is similar to the handshaking and welcoming of friends. The host and server, as well as two hosts, set up a TCP connection. The client requests a client-to-server communication session with the server.

When the server receives an ask, it acknowledges the client-to-server communication session and requests a server-to-client communication session. Then, the initiating client acknowledges the server-to-client communication session.

A diagram illustrating the three-way handshake process for establishing a TCP connection between a Host and a Server. The steps include: Step-1 with Host sending SYN, Server receiving SYN; Step-2 with Server sending SYN ACK, Host receiving SYN ACK; and Step-3 with Host sending ACK, establishing the connection, with arrows indicating the flow of packets.
Master TCP Connection Establishment and Termination – Boost Your Skills (Updated 2025) 4

TCP Session Termination

After the connection is established and the job is completed, the network terminates the connection. The FIN control flag must be set in the segment header for connection termination. To end each one-way TCP session, a two-way handshake, with a FIN segment and an Acknowledgment (ACK) segment, is used. So, to end a single TCP conversation, four exchanges are required to end both sessions. The figure below illustrates the session termination process.

A diagram illustrating the TCP connection termination process between a Host and a Server, showing the exchange of FIN and ACK packets. The sequence includes Host sending FIN, Server receiving FIN and sending ACK, Server sending FIN, and Host receiving FIN and sending ACK, with arrows indicating the flow of packets.
Master TCP Connection Establishment and Termination – Boost Your Skills (Updated 2025) 5

1 – When a host sends all data and no more data remains to be sent in the stream, it sends a segment with the FIN flag set to the server.

2 – The Server sends an ACK to acknowledge the receipt of the FIN to finish the session from the host to the server.

3 – The server sends a FIN to the host to finish the server-to-host session.

4 – The host responds with an ACK to acknowledge the FIN from the server.

When segment acknowledgment is received, the session is terminated.

TCP Connection Lifecycle Simulator

TCP Connection Lifecycle Simulator

Host
Server
Step 1: Host → SYN → Server
Step 2: Server → SYN-ACK → Host
Step 3: Host → ACK → Server
SYN
SYN-ACK
ACK

TCP 3-Way Handshake (Connection Establishment):

  1. SYN: Client sends SYN packet to initiate connection
  2. SYN-ACK: Server responds with SYN-ACK packet
  3. ACK: Client sends ACK packet to complete handshake

After this process, the TCP connection is established and data transfer can begin.

FAQs

  • What is the TCP three-way handshake?

    The TCP three-way handshake establishes a connection with three steps: the Host sends a SYN, the Server responds with a SYN ACK, and the Host sends an ACK. This ensures a reliable connection before data transfer begins.

     

  • How does TCP connection termination work?

    TCP termination uses a four-way handshake: the Host sends a FIN, the Server acknowledges with an ACK and sends its FIN, the Host acknowledges with an ACK. This process gracefully closes the connection.

  • Why is the three-way handshake important in TCP?

    The three-way handshake is crucial for synchronizing sequence numbers and confirming both Host and Server are ready. It prevents data loss and ensures a stable connection for communication.

  • What happens during the TCP four-way termination?

    During TCP four-way termination, both sides close their send and receive channels separately. The Host initiates with a FIN, the Server responds with an ACK and its FIN, and the Host finalizes with an ACK.

  • Can TCP connections be terminated abruptly?

    TCP connections are designed for graceful termination, but an abrupt close can occur due to errors or timeouts. This may lead to data loss, unlike the controlled four-way handshake process.