TCP (Transmission Control Protocol) connection establishment process is commonly referred to as the three-way handshake. This process ensures a reliable session between the client and server. The basic steps of the three-way handshake are as follows:
-
SYN (Synchronize) Step: The client initiates the connection process by sending a TCP segment with the SYN (Synchronize) flag set, indicating its willingness to establish a connection and providing its Initial Sequence Number (ISN) for synchronization.
-
SYN-ACK (Synchronize-Acknowledge) Step: Upon receiving the client's SYN request, the server sends a TCP segment to the client if it agrees to establish the connection. This segment sets both the SYN and ACK (Acknowledgment) flags. The ACK flag acknowledges the client's ISN, while the server's SYN flag provides its own Initial Sequence Number.
-
ACK (Acknowledgment) Step: The client then sends another TCP segment to the server, which sets only the ACK flag to acknowledge the server's ISN. Once this step is completed, both parties have confirmed each other's ISNs and can begin data transmission.
Let me use a simple example to illustrate this process:
Assume Alice wants to establish a TCP connection with Bob's server:
- Alice -> Bob: Alice sends a TCP segment with the SYN flag set to 1 and the Initial Sequence Number set to 100 (assumed value).
- Bob -> Alice: After receiving Alice's request, Bob sends a TCP segment as a response. This segment has both the SYN and ACK flags set to 1, with the acknowledgment number set to Alice's ISN + 1, i.e., 101, and Bob provides its own Initial Sequence Number, set to 300.
- Alice -> Bob: Upon receiving Bob's response, Alice sends a TCP segment with the ACK flag set to 1 and the acknowledgment number set to Bob's ISN + 1, i.e., 301.
After completing these steps, the TCP connection between Alice and Bob is established, allowing them to begin secure and reliable data exchange. This three-way handshake mechanism is the core of TCP reliability, ensuring both parties are ready to receive and send data, and enabling the handling of sequence numbers to track packet transmission order and acknowledgments.