TCP: flow control, congestion control; socket API
GATE CS120 min read
TCP service
Definition. TCP provides a reliable, ordered byte stream between processes. It uses sequence numbers, acknowledgments, retransmissions, checksums, flow control, and congestion control. TCP does not preserve application write boundaries as message boundaries. Example. Two application writes of 20 and 30 bytes may be returned by one receiver read of 50 bytes. Exam point. TCP sequence numbers count bytes, not segments.
TCP segment header
Definition. A TCP segment contains a fixed 20-byte base header plus optional fields. Ports identify endpoints; sequence and acknowledgment numbers support reliable byte delivery; window advertises receive capacity; flags control connection and data behavior. The checksum covers a pseudo-header, TCP header, and data. Example. ACK number 5001 says the receiver expects byte 5001 next. Exam point. A cumulative ACK usually acknowledges all bytes below the stated next-byte number.
| Field | Purpose |
|---|---|
| Source port, destination port | Process/socket endpoints |
| Sequence number | Number of first data byte in this segment |
| Acknowledgment number | Next byte expected when ACK is valid |
| Data offset | TCP header length in 32-bit words |
| Flags | SYN, ACK, FIN, RST, PSH, URG and related bits |
| Window | Receiver-advertised byte capacity |
| Checksum | Error detection over pseudo-header, segment header, data |
| Urgent pointer | Urgent-data indication when used |
| Options | MSS, window scale, timestamps, SACK-related options |
TCP connection establishment
Definition. TCP normally establishes a connection with a three-way handshake: client SYN, server SYN-ACK, client ACK. The exchange synchronizes initial sequence numbers and confirms bidirectional reachability. SYN consumes one sequence number even when it carries no application data. Example. Client ISN=1000, server ISN=7000; SYN-ACK acknowledges 1001 and the final ACK acknowledges 7001. Exam point. ACK values are next expected sequence numbers.
Connection termination
Definition. Each direction of a TCP byte stream closes independently. A FIN consumes one sequence number and is acknowledged; the peer can continue sending until it also closes. TIME_WAIT allows delayed segments to expire and supports retransmission of the final acknowledgment. Example. A FIN at sequence 500 acknowledges as 501. Exam point. FIN is not a reset; RST aborts or rejects a connection.
Sequence numbers and cumulative ACKs
Definition. TCP labels bytes modulo . A segment’s sequence number identifies its first data byte. A cumulative ACK reports the next in-order byte wanted; duplicate ACKs can signal that later data arrived beyond a gap. Example. If bytes 1000–1499 arrive and the next segment is missing, ACK=1500 indicates the next byte expected. Exam point. An ACK does not necessarily identify a particular segment; it can cumulatively cover many bytes.
Retransmission and timeout
Definition. TCP retransmits data that appears lost, typically after a timeout or after enough duplicate ACKs. The retransmission timeout is based on measured RTT and its variation, not a fixed universal value. Exponential backoff lengthens the timeout after repeated failures. Example. If a segment carrying bytes 2000–2499 is lost, the sender can retransmit it; an ACK may cover it and already received later bytes. Exam point. Delayed and variable ACKs require adaptive timeout estimation.
RTT estimation and timeout
Definition. A smoothed RTT estimate combines the previous estimate with a new sample, often with greater weight on the previous value. RTT variation is also estimated to set a safety margin. Retransmitted segments are generally excluded from RTT samples when the ACK’s cause is ambiguous. Example. With ms, sample 120 ms, and weight α=1/8, new SRTT is ms. Exam point. TCP uses a variation term in its timeout, not just the mean RTT.
Receiver flow control
Definition. Flow control prevents a fast sender from overrunning the receiver’s buffer. The receiver advertises a receive window rwnd, reflecting available buffer capacity. The sender limits outstanding unacknowledged data by this advertised window, subject to congestion control too. Example. If receiver buffer space is 20 kB and 8 kB is occupied, the advertised window may be 12 kB. Exam point. rwnd protects the receiver; cwnd protects the network.
Sliding-window byte calculation
Definition. If the sender has transmitted through byte N−1 and has acknowledgment A, the unacknowledged data span is N−A bytes. The sender can send additional bytes while outstanding data remains below the effective window. The usable sender limit is typically . Example. ACK=5000, next sequence=6200, and effective window=4000 bytes. Exam point. Window limits bytes, so do not count segments unless MSS is specified.
Outstanding data is 6200−5000=1200 bytes. The sender can send up to 4000−1200=2800 more bytes before reaching the window limit. If MSS=1000, it can send two full 1000-byte segments and 800 bytes of another, subject to application data availability.
Congestion control purpose
Definition. Congestion control limits the load injected into the network to avoid persistent overload and collapse. TCP sender state includes a congestion window cwnd and often a slow-start threshold ssthresh. The sending window is constrained by both receiver flow control and congestion control. Example. With rwnd=64 kB and cwnd=24 kB, at most 24 kB is outstanding under the simple model. Exam point. Flow control and congestion control use different feedback and protect different resources.
You have read the free 30% of this note
Sign in with Google to keep reading. It is free, takes one tap, and you also get:
- 6 practice questions from this note
- Every note in full, plus the PDF library
- Official past papers as timed tests, with explanations
- An AI tutor for doubts, in Hindi or English
- Your progress, mistakes and study plan saved on every device