Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

TCP Connection Establishment Process: The "Three-Way Handshake"

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

TCP Connection Establishment Process: The "Three-Way Handshake"

We have discussed in earlier topics in this section the connection orientation of TCP and its operation. Before TCP
can be employed for any actually useful purposethat is, sending dataa connection must be set up between the
two devices that wish to communicate. This process, usually called connection establishment, involves an exchange
of messages that transitions both devices from their initial connection state (CLOSED) to the normal operating state
(ESTABLISHED).
Connection Establishment Functions
The connection establishment process actually accomplishes several things as it creates a connection suitable for
data exchange:
o

Contact and Communication: The client and server make contact with each other and establish
communication by sending each other messages. The server usually doesnt even know what client it will be
talking to before this point, so it discovers this during connection establishment.

Sequence Number Synchronization: Each device lets the other know what initial sequence number it
wants to use for its first transmission.

Parameter Exchange: Certain parameters that control the operation of the TCP connection are exchanged
by the two devices.

TCP Connection Establishment Process: The "Three-Way Handshake"


Control Messages Used for Connection Establishment: SYN and ACK
TCP uses control messages to manage the process of contact and communication. There aren't, however, any
special TCP control message types; all TCP messages use the same segment format. A set of control flags in the
TCP header indicates whether a segment is being used for control purposes or just to carry data. As I introduced in
the discussion of the TCP finite state machine, two control message types are used in connection setup, which are
specified by setting the following two flags:
o

SYN: This bit indicates that the segment is being used to initialize a connection. SYN stands for
synchronize, in reference to the sequence number synchronization I mentioned above.

ACK: This bit indicates that the device sending the segment is conveying an acknowledgment for a
message it has received (such as a SYN).

There are also other control bits (FIN, RST, PSH and URG), which aren't important to connection establishment, so
we will set them aside for now. We'll discuss them in other topics. In common TCP parlance, a message with a
control bit set is often named for that bit. For example, if the SYN control bit is set the segment is often called a SYN
message. Similarly, one with the ACK bit set is an ACK message or even just an ACK.

TCP Connection Establishment Process: The "Three-Way Handshake"


Normal Connection Establishment: The "Three Way Handshake"
To establish a connection, each device must send a SYN and receive an ACK for it from the other device. Thus,
conceptually, we need to have four control messages pass between the devices. However, it's inefficient to send a
SYN and an ACK in separate messages when one could communicate both simultaneously. Thus, in the normal
sequence of events in connection establishment, one of the SYNs and one of the ACKs is sent together by setting
both of the relevant bits (a message sometimes called a SYN+ACK). This makes a total of three messages, and for
this reason the connection procedure is called a three-way handshake.

Key Concept: The normal process of establishing a connection between a TCP client and server involves three
steps: the client sends a SYN message; the server sends a message that combines an ACK for the clients SYN
and contains the servers SYN; and then the client sends an ACK for the servers SYN. This is called the TCP

three-way handshake.

Table 152 describes in detail how the three-way handshake works (including a summary of the preparation discussed
in the previous topic). It is adapted from the table describing the TCP finite state machine, but shows what happens
for both the server and the client over time. Each row shows the state the device begins in, what action it takes in that
state and the state to which it transitions. The transmit and receive parts of each of the three steps of the handshake
process are shown in the table, as well as in Figure 211.

Table 152: TCP Three-Way Handshake Connection Establishment Procedure

Client

Start State

Action

Server

Move To State

Start State

CLOSED

The client cannot do


anything until the
server has
performed a passive
OPEN and is ready
to accept a
connection. (Well, it
can try, but nothing
will be
accomplished until
the server is ready.)

CLOSED

CLOSED

Step #1 Transmit:
The client performs
an active OPEN,
creating a
transmission control
block (TCB) for the
connection and
sending a SYN
message to the
server.

SYN-SENT

LISTEN

LISTEN

SYN-SENT

The client waits to


receive an ACK to
the SYN it has sent,

Action

The server
performs a passive
OPEN, creating a
transmission
control block (TCB)
for the connection
and readying itself
for the receipt of a
connection request
(SYN) from a
client.

The server waits


for contact from a
client.

Step #1 Receive,
Step #2 Transmit:
The server

Move To State

LISTEN

SYN-

receives the SYN


from the client. It
sends a single
SYN+ACK
message back to
the client that
contains an ACK
for the client's
SYN, and the
server's own SYN.

RECEIVED

SYNRECEIVED

The server waits


for an ACK to the
SYN it sent
previously.

SYNRECEIVED

Step #3 Receive:
The server
receives the ACK
to its SYN and is
now done with
connection
establishment.

ESTABLISHED

as well as the
server's SYN.

SYN-SENT

Step #2 Receive,
Step #3 Transmit:
The client receives
from the server the
SYN+ACK
containing the ACK
to the client's SYN,
and the SYN from
the server. It sends
the server an ACK
for the server's
SYN. The client is
now done with the
connection
establishment.

ESTABLISHED

The client is waiting


for the server to
finish connection
establishment so
they can operate
normally.

ESTABLISHED

The client is ready


for normal data
transfer operations.

ESTABLISHED

ESTABLISHED

The server is
ready for normal
data transfer
operations.

Figure 211: TCP Three-Way Handshake Connection Establishment Procedure


This diagram illustrates how a conventional connection is established between a client and server, showing the
three messages sent during the process and how each device transitions from the CLOSED state through

intermediate states until the session is ESTABLISHED.

You might also like