Monday, January 20, 2025

Key Mysteries of Network Packet Broker TCP Connections: Demystified the need for Triple Handshake

TCP Connection Setup

When we browse the web, send an email, or play an online game, we often don't think about the complex network connection behind it. However, it is these seemingly small steps that ensure stable communication between us and the server. One of the most important steps is the TCP connection setup, and the core of this is the three-way handshake.

TCP Three-way Handshake Process and State Transitions

TCP is a connection-oriented transport protocol, which requires connection establishment before data transmission. This connection establishment process is done by a three-way handshake.

Initially, both the client and server are CLOSED. First, the server actively listens on a port and is in the LISTEN state, which means that the server must be started. Next, the client is ready to start accessing the webpage. It needs to establish a connection with the server.

When a client initiates a connection, it generates a random initial sequence number (client_isn) and places it in the "Sequence number" field of the TCP header. At the same time, the client sets the SYN flag position to 1 to indicate that the outgoing packet is a SYN packet. The client indicates that it wishes to establish a connection with the server by sending the first SYN packet to the server. This packet does not contain application layer data (that is, data sent). At this point, the status of the client is marked as SYN-SENT.

When a server receives a SYN packet from a client, it randomly initializes its own serial number (server_isn) and then puts that number in the "Serial number" field of the TCP header. Next, the server enters client_isn + 1 in the "Acknowledgement number" field and sets both SYN and ACK bits to 1. Finally, the server sends the packet to the client, which contains no application-layer data (and no data for the server to send). At this time, the server is in SYN-RCVD state.

Once the client receives the packet from the server, it needs to perform the following optimizations to respond to the final reply packet: First, the client sets the ACK bit of the TCP header of the reply packet to 1; Second, the client enters the value server_isn + 1 in the "Confirm answer number" field; Finally, the client sends the packet to the server. This packet can carry data from the client to the server. Upon completion of these operations, the client will enter the ESTABLISHED state.

Once the server receives the reply packet from the client, it also switches to the ESTABLISHED state.

As you can see from the above process, when performing a three-way handshake, the third handshake is allowed to carry data, but the first two handshakes are not. This is a question that is often asked in interviews. Once the three-way handshake is complete, both parties enter the ESTABLISHED state, indicating that the connection has been successfully established, at which point the client and server can start sending data to each other.

Media Contact
Company Name: Transworld (Hong Kong) Co., Limited.
Email:Send Email
Country: China
Website: https://www.mylinking.com/