Back to the 2024 paper

Module 4: Transport Layer & Congestion Control

20247m

Describe a TCP connection. Explain a TCP connection establishment and Connection Release using three way handshaking.

Worked SolutionAI Assisted

TCP connection

TCP (Transmission Control Protocol) is a connection-oriented, reliable, byte-stream transport protocol. A logical connection is set up between two processes before data transfer and closed afterwards.

Features of a TCP connection:

  • Identified by a socket pair: (source IP, source port, destination IP, destination port).
  • Full duplex: data flows in both directions at once.
  • Point-to-point: exactly two endpoints (no multicast).
  • Reliable: sequence numbers, acknowledgements, retransmission, checksum.
  • Byte stream: every byte is numbered; the application data has no message boundaries.
  • Provides flow control (sliding window) and congestion control.

Three phases: connection establishment → data transfer → connection release.

Connection establishment: three-way handshake

   Client                                  Server
     |                                        |   (server does passive open: LISTEN)
     |-- 1. SYN, seq = x ------------------->|   active open
     |                                        |
     |<-- 2. SYN + ACK, seq = y, ack = x+1 ---|
     |                                        |
     |-- 3. ACK, seq = x+1, ack = y+1 ------->|
     |         connection ESTABLISHED         |
  1. SYN: the client sends a segment with the SYN flag set and an initial sequence number x (random). It enters SYN-SENT.
  2. SYN + ACK: the server replies with SYN and ACK set, its own initial sequence number y, and ack = x + 1. It enters SYN-RECEIVED.
  3. ACK: the client acknowledges with ack = y + 1. Both sides are now ESTABLISHED and data can flow.

The SYN segment consumes one sequence number. The handshake synchronises sequence numbers and agrees on parameters (window size, MSS).

Why three steps? Two steps could not confirm that the client received the server's initial sequence number, and old duplicate SYNs could create false connections. SYN flooding (many half-open connections) is a known attack, mitigated with SYN cookies.

Connection release

Each direction is closed separately. The common four-segment exchange is FIN, ACK, FIN, ACK. When the server has no more data, it can combine its ACK and FIN into one segment, which gives the three-way release asked for here.

   Client                                  Server
     |-- 1. FIN, seq = u ------------------->|   client done sending
     |<-- 2. FIN + ACK, seq = v, ack = u+1 ---|   server acknowledges and also closes
     |-- 3. ACK, ack = v+1 ------------------>|
     |   client waits 2×MSL (TIME_WAIT), then closed
  1. FIN: the side that finishes (client) sends a segment with the FIN flag.
  2. FIN + ACK: the server acknowledges it (ack = u + 1) and, having no more data, sets FIN in the same segment.
  3. ACK: the client acknowledges the server's FIN. The server closes when it receives this ACK.

The client stays in TIME_WAIT for 2 × MSL (maximum segment lifetime) so that a lost final ACK can be resent and old segments expire.

Four-way variant: if the server still has data to send after receiving the FIN, it sends a plain ACK first (half-close), later sends its own FIN, and the client sends the last ACK. An abrupt close can also be done with an RST segment.

Similar questions

Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.