In the real world, a handshake is a customary greeting between two people. Similarly, a computer handshake serves as a greeting between two computer systems. It is commonly used to initialize a network connection between two hosts.
A computer handshake may be completed between any two systems that communicate with each other on the same protocol. The two systems may be a client and server or simply two computers on a P2P network. The handshake confirms the identities of the connecting systems and allows additional communication to take place.
Handshaking over a network is commonly called a 3-Way Handshake or "SYN-SYN-ACK." A successful handshake involves seven steps:
- Host A sends a synchronize (SYN) packet to Host B.
- Host B receives Host A's SYN request.
- Host B sends a synchronize acknowledgement (SYN-ACK) message to Host A.
- Host A receive's Host B's SYN-ACK message.
- Host A sends an acknowledge (ACK) message to to Host B.
- Host B receives Host A's ACK message.
- The connection between the two systems is established.
When a system initiates a handshake, there are three possible outcomes:
- No response – If the system receiving the handshake is not available or does not support the protocol the initiating system uses, it may not respond to the request.
- Connection refused – The system receiving the handshake is available and understands the request, but denies the connection.
- Connection accepted – The system receiving the handshake is available, receives the request, and accepts the connection.
The third outcome listed above is the only the one in which the handshake is completed. If a handshake is successful, the two systems can begin communicating and transferring (data) over the established protocol. Examples of protocols that use handshaking include TCP, TLS, and SSL.