Interview surprise: Why does TCP need three-way handshake?

Interview surprise: Why does TCP need three-way handshake?

The reason why TCP needs 3 handshakes is because both sides of the TCP communication are full-duplex, so it takes 3 interactions to confirm the sending and receiving capabilities of both parties, and the TCP handshake must be 3 times. If it is a 2-way handshake, It cannot prove the sending capability of the server and the receiving capability of the client; it cannot be a 4-way handshake, because it has been proved three times, and another interactive handshake is completely unnecessary.

The TCP three-way handshake is a classic interview question. It means that before TCP transmits data, it needs to perform three interactions to formally establish a connection and transmit data. The reason why TCP needs a 3-way handshake is because both sides of TCP are full-duplex. The so-called full-duplex means that either end of the TCP is both the sender and the receiver of data, so this requires both parties to the TCP communication to ensure both their own sending capabilities and their own receiving capabilities. This is like when making a phone call, both parties must ensure that both the microphone (transmitting the sound) and the earphone (receiving the sound) are normal, so that they can communicate effectively. Usually, when making a phone call, it starts like this:

  • Me: Hey, can you hear me?
  • The other party: Can I hear you, can you hear me?
  • Me: I can hear you, so let's talk about business.

The same is true for the TCP three-way handshake. The details of the capabilities of the three-way handshake are as follows:

picture

TCP three-way handshake process

The TCP three-way handshake process is as follows:

  • The client sends a SYN to the server, indicating that it wishes to establish a connection;
  • After the server receives the message, it responds with a SYN and ACK (acknowledgment) to the client;
  • After the client receives the SYN message from the server, it responds with an ACK message.

The specific execution process is shown in the following figure:

picture

Summarize

The reason why TCP needs 3 handshakes is because both sides of the TCP communication are full-duplex, so it takes 3 interactions to confirm the sending and receiving capabilities of both parties, and the TCP handshake must be 3 times. If it is a 2-way handshake, It cannot prove the sending capability of the server and the receiving capability of the client; it cannot be a 4-way handshake, because it has been proved three times, and another interactive handshake is completely unnecessary.

References & Acknowledgements

"Code Efficiently: The Java Development Manual"

"Offer is coming"