Various TCP Connections States
TCP (Transmission Control Protocol) connections progress through a series of states during their lifetime, from establishment to data transfer and finally to termination. These states define the current condition of the TCP connection and dictate how the connection responds to events and network conditions.
Connection Establishment (Three-Way Handshake):
CLOSED: This is the initial state, representing no connection. The socket is not associated with any connection.
LISTEN: The server is passively waiting for incoming connection requests (SYN packets) on a specific port. This is a passive open.
SYN-SENT: The client has sent a SYN (Synchronize) packet to the server to initiate a connection and is waiting for a SYN-ACK (Synchronize-Acknowledge) response. This is an active open.
SYN-RECEIVED: The server has received a SYN packet from the client and has sent back a SYN-ACK packet. It is now waiting for an ACK (Acknowledgement) from the client to establish the connection.
ESTABLISHED: The TCP connection is successfully established, and data transfer can occur between the client and the server. This is the normal state for ongoing communication.
Data Transfer (Occurs within the ESTABLISHED state.
While in the ESTABLISHED state, data is exchanged bidirectionally between the client and server.
Connection Termination (Four-Way Handshake):
FIN-WAIT-1: The local end (client or server) has sent a FIN (Finish) packet to initiate connection termination and is waiting for an ACK of its FIN from the remote end.
FIN-WAIT-2: The local end has received an ACK for its FIN but hasn't yet received a FIN from the remote end. It's waiting for the remote end to also initiate closure.
CLOSE-WAIT: The local end has received a FIN from the remote end and has sent an ACK back. It is now waiting for the local application to close its connection.
CLOSING: This is a less common state. It occurs when one end sends a FIN and simultaneously receives a FIN from the other end. It's waiting for an ACK to the FIN it sent.
LAST-ACK: The local end has closed its connection and sent a FIN, and has received a FIN-ACK from the remote end. It is now waiting for the final ACK to its FIN before fully closing the connection.
TIME-WAIT: After the local end sends the final ACK in the four-way handshake, it enters the TIME-WAIT state for a short period (typically 2 Maximum Segment Lifetimes - 2MSL). This is to ensure that the last ACK reaches the other end and to handle any potential delayed or duplicate packets. After this timeout, the connection fully closes (goes to the CLOSED state).
CLOSED: The connection has been fully terminated, and all resources associated with it are released.
Comments
Post a Comment