COMP30023 · Computer Systems
TCP and Reliable Transport
Week 9 covers TCP's reliability machinery: the three-way handshake and initial sequence numbers, reliable in-order byte-stream delivery with retransmission, and connection teardown with FIN and RST. Computing the SEQ/ACK numbers across the handshake, explaining why SYN and FIN consume a sequence byte, and reasoning about a protocol-design exercise are flagship exam questions.
What this chapter covers
- 01TCP as a reliable, in-order, stream-oriented byte channel; segmenting the stream (often 1460-byte segments)
- 02TCP connection features: full-duplex, end-to-end, byte-stream (no message boundaries preserved), buffered
- 03The 5-tuple naming a connection; key header fields (sequence number, acknowledgement number, window size, flags)
- 04Sequence numbers count bytes not packets; acknowledgement number = next in-order byte expected
- 05The three-way handshake: SYN(x) → SYN-ACK(y, x+1) → ACK(x+1, y+1), agreeing initial sequence numbers
- 06Why the handshake is robust to lost/duplicated setup packets (delayed duplicates); SYN/FIN consume a sequence byte
- 07Connection teardown: FIN is directional (4 segments), RST is an abrupt reset to a non-existent connection
- 08Protocol-design exercise and RPC: stubs, marshalling, and why pointers cannot be passed across address spaces
Sequence and acknowledgement numbers across the three-way handshake
- +1Segment 1, Host 1 → Host 2: SYN with SEQ = x = 3000 (SYN = 1, ACK = 0). This is the connection request; it advertises Host 1's initial sequence number.
- +1Segment 2, Host 2 → Host 1: SYN-ACK with SEQ = y = 8000, ACK = x + 1 = 3001 (SYN = 1, ACK = 1). The ACK = 3001 acknowledges Host 1's SYN and means 'the next byte I expect from you is 3001' — because the SYN consumed sequence number 3000.
- +1Segment 3, Host 1 → Host 2: ACK with SEQ = x + 1 = 3001, ACK = y + 1 = 8001 (SYN = 0, ACK = 1). This acknowledges Host 2's SYN; now both sides have agreed on each other's initial sequence numbers.
- +1The first actual data byte sent by Host 1 carries SEQ = 3001, because the SYN itself consumed one byte of sequence-number space (as a FIN does at close). So data begins one past the initial sequence number.
Key terms
- TCP
- The Transmission Control Protocol: a reliable, in-order, stream-oriented transport that segments an application byte stream into IP datagrams and reconstructs it at the receiver, hiding loss, duplication and reordering. Connections are full-duplex, end-to-end and named by a 5-tuple.
- Sequence number
- A TCP header field counting bytes (not packets). If SYN = 1 it is the initial sequence number; otherwise it is the sequence number of the first data byte in the segment. SYN and FIN each consume one byte of sequence-number space.
- Acknowledgement number
- The next in-order sequence number the ACK sender expects to receive (one past the last contiguously received byte). A missing segment stops it advancing even if later segments have arrived (cumulative acknowledgement).
- Three-way handshake
- TCP connection setup: SYN(SEQ=x) → SYN-ACK(SEQ=y, ACK=x+1) → ACK(SEQ=x+1, ACK=y+1). It ensures exactly one connection forms despite lost/duplicated setup packets and agrees both initial sequence numbers before data flows.
- FIN vs RST
- FIN requests an orderly, directional close — once acknowledged, no new data flows that way, but the other direction can continue; a full close needs four segments. RST is an abrupt hard reset, sent for a packet arriving on a 5-tuple with no open connection (e.g. after a crash).
- RPC (Remote Procedure Call)
- Calling a procedure on a remote machine as if it were local, hiding the networking. Client and server stubs marshal (serialise) and unmarshal arguments and results; pointers cannot be passed because the two processes have separate address spaces.
TCP and Reliable Transport FAQ
How does the TCP three-way handshake work and why three messages?
Host 1 sends SYN with its initial sequence number x; Host 2 replies SYN-ACK with its own initial sequence number y and ACK = x+1; Host 1 sends ACK = y+1. Three messages are needed so both sides confirm each other's initial sequence numbers even when setup packets are lost, duplicated or delayed. If Host 2's SYN-ACK is lost, Host 1 times out and resends the same SYN; Host 2 matches it to its half-open entry and resends the same SYN-ACK — so exactly one connection forms with agreed sequence numbers.
Why do SYN and FIN each consume a sequence number?
So that they can be acknowledged reliably like data. Because the ACK number is 'the next byte I expect', the SYN is assigned one sequence number (say x), and the acknowledgement of it is x+1; the first real data byte therefore starts at x+1. A FIN works the same way at close. Treating SYN and FIN as one byte of sequence space each lets TCP retransmit and acknowledge connection-control segments using exactly the same machinery as data.
What is the difference between a FIN and an RST?
A FIN is an orderly, directional shutdown: it says 'I have no more data to send this way', is acknowledged, and lets the other direction keep flowing until it too sends a FIN, so a full close uses four segments. An RST is an abrupt hard reset with no negotiation — it is sent when a packet arrives for a 5-tuple that has no open connection (for example a stale segment reaching a host that has since crashed and forgotten the connection). FIN is preferred for normal shutdown; RST handles error cases.
Why can't RPC pass pointers between machines?
Because the client and server run in separate address spaces, so a memory address that is valid on the client means nothing on the server. Marshalling can copy the value a pointer refers to, but rebuilding a pointer-linked structure (or an unknown-size array) on the other side is hard, and weakly typed languages like C make it worse because the stub cannot always deduce argument sizes or types. Global variables are not shared either, which is why RPC hides the network but is not perfectly transparent.
Can AI help me with TCP in COMP30023?
Yes. Sia can walk through the three-way handshake SEQ/ACK arithmetic, explain why SYN and FIN consume a sequence byte, trace a handshake with a lost SYN-ACK, or reason through the protocol-design exercise step by step, checking your working. It is a study aid; it does not do your graded exam, quizzes or projects, and University of Melbourne academic-integrity rules apply.
Exam move
TCP is prime exam territory — the handshake SEQ/ACK arithmetic is a recurring question — so drill it until the +1 bookkeeping is automatic. Practise writing all three handshake segments with their SEQ, ACK and SYN/ACK flags for arbitrary initial sequence numbers, and be ready to explain why SYN and FIN each consume a sequence byte and what the first data byte's sequence number is. Learn the robustness argument (how the handshake still forms exactly one connection when the SYN-ACK is lost) and the teardown story (FIN directional, four segments; RST abrupt). Keep the connection-feature list handy (full-duplex, end-to-end, byte-stream with no preserved message boundaries, buffered) and understand the protocol-design/RPC reasoning about stubs, marshalling and why pointers cannot cross address spaces. This also grounds the socket projects; confirm the exam date on Canvas and keep consolidating toward your WAM.
Working through TCP and Reliable Transport in COMP30023? Sia is AskSia’s AI Computer Science tutor — ask any COMP30023 TCP and Reliable Transport question and get a clear, step-by-step explanation grounded in how COMP30023 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.