In This Scenario We Want to Transfer 5000 Bytes of Data to a Server

In This Scenario We Want to Transfer 5000 Bytes of Data to a Server

In this scenario we want to transfer 5000 bytes of data to a server. The process on the server is listening for connections on a well-known port number. The Client is transmitting from a random/user/dynamic port number.

Before data can be transmitted using TCP, the three-way handshaking must be performed.

The client initiates the communication from a randomly selected port number to a predefined target port.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / Options
2000 / 300 / 100 / 0 / Syn / 8192 / MSS=4056

When the server receives this packet it knows that the client is expecting replies on port number 2000, that the client will begin numbering it’s segments at 100, and that the client can receive up to 8192 bytes of data in multiple consecutive packets no larger than 4056 bytes of TCP data each.

The server responds with it’s parameters

Source Port

/ Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / Options
300 / 2000 / 300 / 101 / Syn Ack / 4380 / MSS=1460

Notice the server acknowledged the segment 100 by setting the acknowledgement number to the value of the next sequence number it expects.

The Client now knows that the server will begin its sequence numbers at 300, the server can receive up to 4380 bytes of TCP data in segments no larger than 1460 bytes each.

The Client responds confirming the three-way handshake is complete.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / No Data
2000 / 300 / 101 / 301 / Ack / 4096

The client divides the data into segments of 1460 bytes and transmits the first three, a total of 4380 bytes of data.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / Data
2000 / 300 / 101 / 301 / Ack / 4096 / 1460 B

Notice that this sequence number is the same because during the data transmission phase the sequence numbers go up by the number of data bytes already transmitted.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / Data
2000 / 300 / 1561 / 301 / Ack / 4096 / 1460 B
2000 / 300 / 3021 / 301 / Ack / 4096 / 1460 B

The server receives the first segment and the third segment, the second one is lost. The server notices the missing segment and sends back a TCP message requesting the missing data.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / No Data
300 / 2000 / 301 / 1561 / Ack / 1460

The client reacts to this request by sending 1460 bytes of data beginning at position 1561.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / Data
2000 / 300 / 1561 / 301 / Ack / 4096 / 1460 B

This packet arrives at the server whose buffer is now full. It immediately informs the operating system that data is ready for the upper layer process and sends back an acknowledgement.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / No Data
300 / 2000 / 301 / 4481 / Ack / 0

Since the receive window on the server is full, the client must wait until the server transmits a TCP packet indicating free space in the buffer. When the upper layer process on the servers removes the received data from the buffer the server transmits the following.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / No Data
300 / 2000 / 301 / 4481 / Ack / 4380

The client can now send the next segment, since it is the last segment; the client sets the Push flag to request an immediate acknowledgement from the server.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / Options or Data
2000 / 300 / 4481 / 301 / Ack Push / 4096 / 620 B

The server reacts to the Push flag by immediately sending back an acknowledgement and informing the upper layer process that data is available.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / Options or Data
300 / 2000 / 301 / 5101 / Ack / 3760

The client has received an acknowledgement for all the data it has sent and is ready to terminate the connection. Sending a simple TCP header with the Ack and Fin bits set indicates this. The conversation is no longer in a data transfer phase so Sequence Numbers increase by one.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / Options or Data
2000 / 300 / 5101 / 302 / Ack Fin / 4096

The server acknowledges the clients intention to end the session and also send back a FIN bit to confirm it’s willingness to end the session.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / Options or Data
300 / 2000 / 302 / 5102 / Ack Fin / 4380

The client sends back a simple TCP packet acknowledging that the session is ended.

Source Port / Destination Port / Sequence Number / Acknowledgement Number /

Control Code Flags

/ Receive Windows Size / Options or Data
2000 / 300 / 5102 / 303 / Ack / 4096