TCP Connection Establishment and Termination

All application processes on the server use different port numbers. The network administrator can use default ports or configure ports manually for these applications. We cannot use the same port numbers on the same server for different applications. For example, we cannot configure the same port number for the FTP and web servers (for example, port 80 or port 21 for both).

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.

Connection Establishment

When two persons 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. The figure below illustrates the establishment of the TCP connection.

Session Termination

After the connection is established and the job is completed, the network terminates the connection. For connection termination, the FIN control flag must be set in the segment header. 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.

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 host to 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 acknowledgement is received, the session is terminated.