To establish a
connection, TCP uses a three-way handshake. Before a client attempts to connect
with a server, the server must first bind to a port to open it up for
connections: this is called a passive open. Once the passive open is
established, a client may initiate an active open.
To establish a
connection, the three-way (or 3-step) handshake occurs:
1. The active
open is performed by the client sending a SYN to the server.
2. In response,
the server replies with a SYN-ACK.
3. Finally the
client sends an ACK back to the server.
At this point,
both the client and server have received an acknowledgment of the connection.
Example:
1. The
initiating host (client) sends a synchronization packet (SYN flag set to 1) to
initiate a connection. It sets the packet's sequence number to a random value x.
2. The other
host receives the packet, records the sequence number x from the client,
and replies with an acknowledgment and synchronization (SYN-ACK). The Acknowledgment
is a 32-bit field in TCP segment header. It contains the next sequence number
that this host is expecting to receive (x + 1). The host also initiates
a return session. This includes a TCP segment with its own initial Sequence
Number of value y.
3. The
initiating host responds with the next Sequence Number (x + 1) and a
simple Acknowledgment Number value of y + 1, which is the Sequence
Number value of the other host + 1.
Figure:- Three-way handshake
* Each SYN message during connection establishment can specify options such as maximum segment size (MSS), window scaling and time stamps.
* The three way handshake procedure ensures that both host’s agree on their initial sequence numbers.
Let us consider a situation why the initial sequence number must be different at every time and what happened if a host can always use the same initial sequence number.
Figure: -
Justifying a three way handshake: If a host always uses the same initial
sequence, old
segments cannot be distinguished from the current ones.
In above case, after connection
is established, a delayed segment from the previous connection arrives.
Host B accepts
this segment, since the sequence number is legal.
If a segment from current
connection arrives later, it will be rejected by host B, thinking that the
segment is a duplicate. Thus host B cannot distinguish a delayed segment from
the new one.
The below figure
is an example for client server application
0 comments