The three-way handshake creates a reliable OSI Layer 4 connection between two hosts (identified via TCP sockets).The handshake process includes the TCP port numbers that will be used by each host, respectively.The steps required for a three-way handshake are as follows:

  1. The first segment is a connection request (SYN) segment carrying the socket of the requesting host.Included is the initial sequence number for that host.
  2. The second segment is an acknowledgement (ACK) for the first host’s SYN request.Included is the second host’s connection request (SYN), plus the second host’s own initial sequence number.
  3. The third segment is the first host’s acknowledgment (ACK) for the second host’s SYN request.