Security – TCP connection handshake

protocolsSecuritytcp

Why is in TCP a 3-way handshake used during establishing a connection? Meaning, why it is not enough to use a 2-way handshake?

Best Answer

The handshaking mechanism used in TCP is designed so that two hosts, attempting to communicate, can negotiate the parameters of the network connection before beginning the communication. Both sides can assume that the other computer is ready and start to reliably send data.

Here is a simplified diagram of the packets being sent on both sides during the handshake:

        SYN     ->
                    SYN received
Host A          <-       SYN ACK    Host B
        SYN ACK received
        ACK     ->           
                    ACK received

      TCP connection is established

SYN (synchronize) and ACK (acknowledge) messages are specified by a bit/number inside the TCP header of the segment.

The process is also designed so that both ends can initiate and negotiate separate connections at the same time.

In order to end a connection between two computers, another 3-way communication is performed to tear down the TCP connection. The initiation and teardown of a TCP connection is part of what makes TCP a reliable protocol.

See also: What is the difference between UDP and TCP?