Skip to main content

Server before client; TCP reliability

Short answer

The server must run first to perform passive open (listen/accept); otherwise the client's SYN receives an RST. TCP provides reliability via a three-way handshake, sequence numbering, cumulative ACKs, retransmission on timeout/duplicate ACKs, checksums, and flow/congestion control.

For a client-server application over TCP, why must the server program be executed before the client program? TCP is known as a reliable process, describe how reliability is provided by TCP.

Why the server must run before the client

TCP is connection-oriented: a connection must be set up before data is sent. The server performs a passive open: it creates a socket, binds it to a well-known port, calls listen() and waits in accept(). The client performs an active open by sending a SYN to the server's IP and port.

  • If the server is not running, no process is listening on that port. The server's TCP replies with RST, and the client gets "connection refused".
  • The client needs the server's address and port, which the server program makes available by binding.
  • The server must be ready to accept requests from any number of clients that may arrive at any time.
Server: socket -> bind -> listen -> accept (waits)
Client: socket -> connect ------------>  SYN
                         <------------  SYN+ACK
                         ------------>  ACK   (connected)

How TCP provides reliability

  1. Connection establishment: the three-way handshake (SYN, SYN+ACK, ACK) makes sure both sides are ready and agree on initial sequence numbers.
  2. Sequence numbers: every byte is numbered, so the receiver can reorder segments and discard duplicates.
  3. Acknowledgements: the receiver sends a cumulative ACK with the next expected byte number.
  4. Retransmission: if the ACK does not arrive before the retransmission timeout (RTO), the segment is sent again; three duplicate ACKs trigger fast retransmit.
  5. Checksum: the receiver discards corrupted segments; since no ACK comes back, the sender retransmits them.
  6. Flow control: the window size in the ACK stops the sender from overflowing the receiver's buffer.
  7. Congestion control: slow start, congestion avoidance and fast recovery reduce the sending rate when the network is congested.
  8. Connection termination: FIN/ACK exchange ensures all data is delivered before closing.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Networks and Security chapter 5 questions →