Glossary#
| Term | Plain meaning | Chapter |
|---|---|---|
| port | 16-bit number for which program on a machine | 1 |
| well-known / ephemeral port | fixed server port (443) / random client port | 1 |
| five-tuple | protocol + source IP/port + destination IP/port = one connection | 1 |
| socket | kernel object a program uses for networking; a file descriptor | 2 |
| bind / listen / accept / connect | attach to address:port / start accepting / take one caller / dial out | 2 |
0.0.0.0 vs 127.0.0.1 binding | reachable from anywhere vs only this machine | 2 |
| UDP / datagram | no-guarantee transport / one UDP message | 3 |
| TCP / segment | reliable ordered byte-stream transport / one TCP chunk | 4 |
| byte stream | data with order but no message boundaries | 4 |
| three-way handshake | SYN, SYN-ACK, ACK | 5 |
| sequence number | position of a segment's first byte in the stream | 5, 6 |
| RTT | round trip time | 5 |
| SYN flood / SYN cookies | half-open connection attack / the defence | 5 |
| refused vs timeout | nothing listening (RST) / nothing replied (often a firewall) | 5, 11 |
| ACK (cumulative) | "I have everything before byte n" | 6 |
| retransmission / RTO / fast retransmit | resending / how long to wait / resend on 3 duplicate ACKs | 6 |
| flow control / receive window | don't overwhelm the receiver / its free space | 7 |
| congestion control / congestion window | don't overwhelm the network / the sender's guess | 7 |
| slow start | begin small, double each RTT | 7 |
| FIN / RST | polite close / abrupt kill ("connection reset by peer") | 8 |
| LISTEN / ESTABLISHED / TIME_WAIT / CLOSE_WAIT | connection states (CLOSE_WAIT piling up = our bug) | 8 |
| TCP keep-alive | probes to detect dead idle connections | 8 |
| head-of-line blocking | one loss stalls everything behind it | 9 |
| QUIC | UDP-based transport with independent streams; carries HTTP/3 | 9 |
| NAT / NAT table | rewriting private source address+port to public / the mapping | 10 |
| port forwarding | fixed rule sending a public port to a private device | 10 |
| CGNAT | ISP-level NAT shared by many customers | 10 |
| NAT gateway | cloud service letting private servers call out | 10 |
| firewall (stateful / stateless) | allow/deny rules (remembers connections / doesn't) | 11 |
| security group / network ACL | AWS stateful per-server / stateless per-subnet rules | 11 |
| least privilege | open only exactly what's needed | 11 |
| latency / bandwidth | time per trip / data per second | 12 |
| keep-alive (HTTP) / connection reuse | many requests over one connection | 12 |
| connection pool | ready-made open connections shared by handlers | 12 |
Cheat Sheet#
Ports to know
22 SSH 53 DNS 80 HTTP 443 HTTPS 5432 Postgres 3306 MySQL 6379 Redis 27017 MongoDB
dev: 8000 FastAPI · 3000 React/Next · 5173 Vite privileged (Linux, root only): 0–1023TCP in one screen
open: SYN → SYN-ACK → ACK (1 RTT before data)
data: sequence numbers + cumulative ACKs; resend on timeout or 3 dup ACKs
speed: min(receive window, congestion window); slow start doubles per RTT
close: FIN/ACK each way (polite) · RST (abrupt)
states: LISTEN · ESTABLISHED · TIME_WAIT (normal, 60 s on Linux) · CLOSE_WAIT (our bug)Symptoms → likely cause
"connection refused" host reachable, nothing listening on that port
"connection timed out" firewall/security group dropping, or no route
"connection reset by peer" peer/LB/NAT killed it — often an idle pooled connection
"address already in use" another process listens on that port (lsof -i :PORT)
works locally, not remotely bound to 127.0.0.1 — bind 0.0.0.0
thousands of CLOSE_WAIT our code isn't closing socketsRound-trip maths
new HTTPS connection ≈ 3 RTT to first response (TCP + TLS 1.3 + request) · reused ≈ 1 RTT
time ≈ round trips × RTT + size ÷ bandwidth → for small data, latency dominatesCommands (macOS · Linux)
who listens on a port lsof -i :8000 · ss -tlnp
all connections + state netstat -an | grep 443 · ss -tan
raw TCP client/server nc -l 9000 / nc localhost 9000
test a port is open nc -vz 13.235.10.20 443
see HTTP + connection curl -v https://example.comTry This Yourself#
Handshake with netcat. Run
nc -l 9000in one terminal andnc localhost 9000in another. In a third, runnetstat -an | grep 9000and find theLISTENsocket and the twoESTABLISHEDends (one for each direction of the conversation, with different ports). Close the client with Ctrl+C, run the command again, and look forTIME_WAIT.Refused vs timeout. Run
nc -vz localhost 9999(nothing listening → refused, instant). Then runnc -vz -G 5 10.255.255.1 80(an unreachable private address → times out after 5 seconds; on Linux use-w 5instead of-G 5). Feel the difference.See connection reuse. Run
curl -v https://example.com https://example.com(the same URL twice in one command). In the output, look for "Re-using existing connection" on the second request — no second handshake.