Master the fundamental concepts of tcp/ip from scratch through this focused micro-challenge.
TCP is full-duplex: each direction closes independently. A normal teardown takes four segments. For example, the active closer on port 8080 sends FIN, the passive side ACKs, then sends its own FIN, and the active side sends the final ACK.
Active closer: ESTABLISHED -> FIN_WAIT_1 -> FIN_WAIT_2 -> TIME_WAIT -> CLOSED
Passive closer: ESTABLISHED -> CLOSE_WAIT -> LAST_ACK -> CLOSED
The FIN flag consumes one sequence number, just like SYN. After the final ACK, the active closer sits in TIME_WAIT for 2 x MSL (typically 60-120 seconds) to catch retransmitted FINs and reject stale segments from old connections.
RST aborts immediately with no graceful shutdown. Common triggers:
9999 with no listener)This task requires you to simulate the FIN/ACK sequence with state transitions. TIME_WAIT accumulation from this close pattern is a well-known production incident for high-throughput servers like nginx, which is why SO_REUSEADDR exists. Operators tune net.ipv4.tcp_tw_reuse and related sysctls because thousands of connections to port 443 can leave the server holding sockets in TIME_WAIT for 60-120 seconds each.
Implement a simulation of TCP connection teardown.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github