Handshaking is an automated process of negotiation that dynamically sets parameters of a communications channel established between two entities before normal communication over the channel begins.
It is usually a process that takes place when a computer is about to communicate with a foreign device to establish rules for communication.
TCP three-way handshake
TCP three-way handshake is the method used by TCP set up a TCP/IP connection over an Internet Protocol based network.
It’s commonly referred to as “SYN-SYN-ACK”.
- Host A sends a TCP SYNchronize packet to Host B
- Host B receives A’s SYN
- Host B sends a SYNchronize-ACKnowledgement
- Host A receives B’s SYN-ACK
- Host A sends ACKnowledge
- Host B receives ACK.
- TCP socket connection is ESTABLISHED.
Alternatively, there’s a good illustration on wiki:
Establishing a normal TCP connection requires three separate steps:
The first host (Alice) sends the second host (Bob) a “synchronize” (SYN) message with its own sequence number x, which Bob receives.
Bob replies with a synchronize-acknowledgment (SYN-ACK) message with its own sequence number y and acknowledgement number x + 1, which Alice receives.
Alice replies with an acknowledgment message with acknowledgement number y + 1, which Bob receives and to which he doesn’t need to reply.
Two more thing
Note that FTP, Telnet, HTTP, HTTPS, SMTP, POP3, IMAP, SSH and any other protocol that rides over TCP also has a three way handshake performed as connection is opened.
TCP ‘rides’ on top of Internet Protocol (IP) in the protocol stack. IP handles IP addressing and routing and gets the packets from one place to another, but TCP manages the actual communication sockets between endpoints.