TCP: flow control and congestion control; socket API
TCP sequence numbers and connection setup, flow control with the receive window, congestion control (slow start, congestion avoidance, fast retransmit and recovery), retransmission timers, and the socket API calls.
TCP gives a reliable, in-order, connection-oriented byte stream between two processes, identified by (source IP, source port, destination IP, destination port).
Sequence numbers count bytes, not segments. A segment's sequence number is the number of its first data byte.
The acknowledgement number is the next byte the receiver expects; ACKs are cumulative.
SYN and FIN each consume one sequence number even though they carry no data.
The header is 20 bytes without options, up to 60 bytes with options (header length is a 4-bit field counting 32-bit words).
Three-way handshake: client sends SYN (seq ); server replies SYN-ACK (seq , ack ); client sends ACK (seq , ack ). The first data byte from the client then has sequence number .
Closing takes four segments in general (FIN, ACK in each direction); the side that closes first waits in TIME_WAIT for MSL before the connection is gone, so stray old segments die out.
Wrap-around: the 32-bit sequence space holds bytes. At a sending rate of bytes per second, sequence numbers repeat after seconds. On fast links this can be shorter than the segment lifetime, which is why the timestamp option (PAWS) exists.
2. Flow control: the receive window
Flow control stops a fast sender from overflowing the receiver's buffer. The receiver advertises a receive window (free buffer space) in every segment; the sender keeps
where is the congestion window. So the effective window is .
The window field is 16 bits, so bytes unless the window scale option is used; it multiplies the field by with .
At most one window of data is sent per round trip, so throughput .
To use a link fully the window must cover the bandwidth-delay product: .
If the sender stops and runs a persist timer, sending small probes until the window opens.
Silly window syndrome (tiny segments): Nagle's algorithm on the sender and delayed window updates on the receiver avoid it.
Flow control protects the receiver; congestion control protects the network. Keep the two apart in MSQ statements.
3. Congestion control
The sender keeps a congestion window and a slow-start threshold . GATE questions count in MSS per transmission round (one RTT).
Slow start (): start at MSS and add 1 MSS per ACK, so doubles every RTT.
Congestion avoidance (): add 1 MSS per RTT (additive increase).
Timeout: , MSS, back to slow start.
Three duplicate ACKs:fast retransmit the missing segment. TCP Reno then does fast recovery: and (plus 3 MSS while the duplicates are counted), continuing in congestion avoidance. TCP Tahoe treats it like a timeout ().
Halving on loss and adding 1 per RTT is AIMD (additive increase, multiplicative decrease), which gives the sawtooth shape of Reno.
Convention for the threshold: if doubling would jump past , most GATE solutions set for that round and then grow linearly. Read the question; choose numbers carefully when tracing round by round, and write the window at the start of each round.
Slow start to ssthresh = 8, linear growth to 16, a timeout, then a new ssthresh of 16/2 = 8.
4. Retransmission timer
TCP retransmits a segment if its ACK does not arrive within the retransmission timeout (RTO). The RTO must track the round-trip time, which varies.
Exponentially weighted moving average of measured samples:
The older original scheme used ; use whichever the question states.
Karn's algorithm: do not take RTT samples from retransmitted segments (the ACK is ambiguous), and double the RTO after each timeout (exponential backoff).
Fast retransmit usually recovers a single loss before the timer fires, because three duplicate ACKs arrive within about one RTT.
When a question gives several samples, apply the update once per sample, in order, carrying the new estimate forward. If it asks for both EstRTT and DevRTT, follow the order it specifies, since different texts update them in different orders.
5. The socket API
Applications use TCP and UDP through sockets. The usual blocking call sequence is:
Server (TCP)
Client (TCP)
socket() create endpoint
socket()
bind() attach local address and port
(optional bind())
listen() mark as passive, set backlog
accept()blocks until a client connects; returns a new connected socket
connect() starts the three-way handshake
recv() / send()
send() / recv()
close()
close() sends FIN
Points GATE tests:
listen() does not block and does not accept; accept() blocks.
The listening socket keeps listening; each accept() returns a separate socket per client, so a server can serve many clients on the same port.
connect() on a TCP socket triggers the handshake; it returns after the SYN-ACK arrives.
UDP has no connection: socket(), bind() (server), then sendto() / recvfrom() with the peer address each time. There is no listen() or accept().
bind() with a port already in use fails.
Formulas to remember
Effective window
Throughput bound
Window to fill the pipe
Sequence number wrap-around time
RTT estimate usually
Deviation estimate usually
Timeout
On timeout
Common mistakes
Forgetting that SYN and FIN consume a sequence number, which shifts every later byte number by one.
Confusing flow control (receiver buffer, rwnd) with congestion control (network, cwnd); the sender uses the minimum of the two.
Treating three duplicate ACKs like a timeout in TCP Reno; only Tahoe drops cwnd to 1 MSS.
Mixing bytes and bits in throughput: window in bytes times 8, divided by RTT in seconds.
Saying listen() blocks or that accept() reuses the listening socket.
Doubling cwnd past ssthresh during slow start without checking the convention the question uses.
Worked examples
Try each step yourself, then reveal the working.
Example 1: Tracing the congestion window
numerical
TCP starts with cwnd = 1 MSS and ssthresh = 8 MSS. Every transmission round succeeds until a timeout occurs in round 12. Give cwnd for rounds 1 to 17.
Step 1: Slow start: double each round until ssthresh.
Try it on paper first.
Example 2: Window-limited throughput and window scaling
numerical
A TCP connection has RTT 20 ms and the receiver advertises the maximum unscaled window of 65,535 bytes. (a) What is the maximum throughput? (b) On a 1 Gbps link with RTT 10 ms, what is the smallest window scale shift that lets the window fill the pipe?
Step 1: (a) Divide one window by one RTT.
Try it on paper first.
Example 3: Sequence number wrap-around
numerical
How long does it take for TCP sequence numbers to wrap around on a 1 Gbps link sending at full rate? And on a 10 Gbps link?
Step 1: Convert the rate to bytes per second.
Try it on paper first.
Example 4: Which socket call does what?
conceptual
A TCP server calls socket, bind, listen and accept; a client calls socket and connect. At which call does the three-way handshake happen, and which calls block?
Step 1: Where does the SYN come from?
Try it on paper first.
Previous year questions
19 official GATE CSE questions on this topic, newest first.
10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.
Mark as mastered
Loading your progress…
My revision notes
Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.