You are on page 1of 4

TCP - Transmission Control Protocol (TCP Connection Setup and Release) Client Node Internet Server Node Client

Network Server Client App Client Socket Network Server Socket Server App

EventHelix.com/EventStudio 1.0 17-Mar-02 13:02 (Page 1)

Copyright (c) 2002 EventHelix.com Inc. All Rights Reserved. LEG: About TCP TCP (Transmission Control Protocol) provides a reliable end to end service that delivers packets over the Internet. Packets are delivered in sequence without loss or duplication. Server Application creates a Socket Closed The Socket is created in Closed state seq_num = 100 Server sets the initial sequence number to 100 Passive_Open Server application has initiated a passive open. In this mode, the socket does not attempt to establish a TCP connection. The socket listens for TCP connection request from clients Listen Socket transitions to the Listen state Client Application creates Socket The socket is created in the Closed state Initial sequence number is set to 0 Application wishes to communicate with a destination server using a TCP connection. The application opens a socket for the connection in active mode. In this mode, a TCP connection will be attempted with the server. Typically, the client will use a well known port number to communicate with the remote Server. For example, HTTP uses port 80. LEG: Client initiates TCP connection Client initiated three way handshake to establish a TCP connection SYN
src = Client_Port, dst = Server_Port, seq_num = _0 SYN Sent

create

create
Closed seq_num = 0

Active_Open

SYN
src = Client_Port, dst = Server_Port, seq_num = _0

Client sets the SYN bit in the TCP header to request a TCP connection. The sequence number field is set to 0. Since the SYN bit is set, this sequence number is used as the initial sequence number Socket transitions to the SYN Sent state SYN TCP segment is received by the server Server sets the SYN and the ACK bits in the TCP header. Server sends its initial sequence number as 100. Server also sets its window to 65535 bytes. i.e. Server has buffer space for 65535 bytes of data. Also note that the ack sequence numer is set to 1. This signifies that the server expects a next byte sequence number of 1 Now the server transitions to the SYN Received state

SYN_ACK
src = Server_Port, dst = Client_Port, seq_num = _100, ack_num = _1, window = _65535

SYN Received

TCP - Transmission Control Protocol (TCP Connection Setup and Release) Client Node Internet Server Node Client Network Server Client App Client Socket Network Server Socket Server App SYN_ACK
src = Server_Port, dst = Client_Port, seq_num = _100, ack_num = _1, window = _65535

EventHelix.com/EventStudio 1.0 17-Mar-02 13:02 (Page 2)

Client receives the SYN_ACK TCP segment

ACK
src = Client_Port, dst = Server_Port, ack_num = _101, window = _5000 Established

ACK
src = Client_Port, dst = Server_Port, ack_num = _101, window = _5000 Established

Client now acknowledges the first segment, thus completing the three way handshake. The receive window is set to 5000. Ack sequence number is set to 101, this means that the next expected sequence number is 101. At this point, the client assumes that the TCP connection has been established Server receives the TCP ACK segment

Now the server too moves to the Established state LEG: Short data transfer Data transfer phase: Here a short data transfer takes place, thus TCP slow start has little impact Data
size = _1024 Split data into TCP segments

Client application sends 1024 bytes of data to the socket This TCP connection limits TCP segments to 512 bytes, thus the received data is split into 2 TCP segments The first TCP segment is sent with a sequence number of 1. This is the sequence number for the first byte in the segment. (Note that unlike other protocols, TCP maintains sequence numbers at byte level. The sequence number field in the TCP header corresponds to the first byte in the segment.) Bytes in the first TCP segment correspond to 1 to 512 sequence numbers. Thus, the second TCP segment contains data starting with 513 sequence number

TCP_Segment
seq_num = _1, len = _512

TCP_Segment
seq_num = _513, len = _512

TCP_Segment
seq_num = _1, len = _512

TCP_Segment
seq_num = _513, len = _512 Assemble TCP Segments

Server receives both the segments Server receives two consecutive segments, thus it assembles the segments Assembled Data is passed to the Server Application Server acknowledges the data segments with the next expected sequence number as 1025 (TCP typically sends an acknowledgement every two received segments)

Data
size = _1024

ACK
ack_num = _1025

ACK
ack_num = _1025

Data
size = _700

Now server responds back with data for the client

TCP - Transmission Control Protocol (TCP Connection Setup and Release) Client Node Internet Server Node Client Network Server Client App Client Socket Network Server Socket Server App
Split data into TCP segments

EventHelix.com/EventStudio 1.0 17-Mar-02 13:02 (Page 3)

TCP_Segment
seq_num = _101, len = _512

TCP_Segment
seq_num = _613, len = _188

TCP_Segment
seq_num = _1, len = _512

TCP_Segment
seq_num = _613, len = _188 Assemble TCP Segments

Client has received both the TCP segments

Data
size = _700

Socket passes data to Client application ACK


ack_num = _701

Client sends a TCP ACK with the next expected sequence number set to 701 ACK
ack_num = _701

LEG: Client initiates TCP connection close Client initiates TCP connection close Close FIN
FIN Wait 1

FIN ACK
Close Wait

ACK
FIN Wait 2

Close FIN
Last Ack

FIN ACK Close_Timer

Client application wishes to release the TCP connection Client sends a TCP segment with the FIN bit set in the TCP header Client changes state to FIN Wait 1 state Server receives the FIN Server responds back with ACK to acknowledge the FIN Server changes state to Close Wait. In this state the server waits for the server application to close the connection Client receives the ACK Client changes state to FIN Wait 2. In this state, the TCP connection from the client to server is closed. Client now waits close of TCP connection from the server end Server application closes the TCP connection FIN is sent out to the client to close the connection Server changes state to Last Ack. In this state the last acknowledgement from the client will be received Client receives FIN Client sends ACK Client starts a timer to handle scenarios where the last ack has been lost and server resends FIN

TCP - Transmission Control Protocol (TCP Connection Setup and Release) Client Node Internet Server Node Client Network Server Client App Client Socket Network Server Socket Server App
Time Wait

EventHelix.com/EventStudio 1.0 17-Mar-02 13:02 (Page 4)

ACK
Closed

Client waits in Time Wait state to handle a FIN retry Server receives the ACK Server moves the connection to closed state delete

Close_Timer
Closed

Close timer has expired. Thus the client end connection can be closed too.

delete

You might also like