Networking Engineering / TCP, UDP & CONNECTION LIFECYCLE / NET-006
TCP Handshake Capture
Explore concept graphMateri
Masalah: API tidak menerima request meskipun proses backend berjalan. Apakah TCP tidak terbentuk, data harus dikirim ulang, atau koneksinya justru sudah ditutup?
Langkah pertama: gambar SYN → SYN-ACK → ACK. Labeli client, server, source/destination IP dan port. Handshake ini terjadi pada TCP sebelum payload aplikasi dapat diterima sebagai stream terhubung.
Client Server
CLOSED LISTEN
SYN seq=x ───────────────>
<─────────────── SYN+ACK seq=y ack=x+1
ACK ack=y+1 ───────────────>
ESTABLISHED ESTABLISHED
data: bytes m..n ───────────────>
<─────────────── ACK: next expected byte
[when needed: timeout / retransmission of unACKed data]
FIN ───────────────>
<─────────────── ACK
<─────────────── FIN (when peer closes)
ACK ───────────────>Membaca sequence dan ACK
Jika client memulai SYN seq=100 dan server merespons SYN+ACK seq=300 ack=101, ACK client untuk SYN server adalah ack=301. Wireshark sering menggunakan relative sequence numbers, jadi nilai awal dapat tampil sebagai 0 dan ACK berikutnya 1. Selalu jelaskan apakah tampilan memakai relative atau absolute sequence numbers.
Packet loss dan congestion dapat menyebabkan retransmission, tetapi tidak otomatis terjadi saat eksperimen lokal. RFC 6298 mengatur retransmission timeout dan backoff; repeated SYN atau data tidak membuktikan HTTP 503 tanpa respons HTTP yang benar-benar diterima.
Konsep 1 / 3
Read SYN, SYN-ACK and ACK sequence and acknowledgement fields from a real TCP connection trace.
A successful socket connect means the transport is established, but without packet evidence the engineer cannot explain why earlier SYN attempts failed.
Draw SYN → SYN+ACK → ACK and label who sends each packet.
Intuisi utama
Client SYN carries ISN=x; server SYN-ACK acknowledges x+1 and announces ISN=y; client ACK acknowledges y+1. The application byte stream is delivered after establishment.
RFC 9293 Figure 6 shows SYN, SYN+ACK and ACK. The SYN itself uses one sequence-space position. An ACK-only segment does not consume sequence space. Capture direction, source/destination IP and ports, flag bits, seq and ACK values; Wireshark usually shows relative sequence numbers so x and y may appear as 0. A SYN without SYN-ACK is not itself proof of a specific firewall rule: routing, drops and remote host availability must be investigated with corroborating evidence. Node's connect event occurs after a successful connection setup but does not reveal the three packets.
Contoh bertahap
A local client connects to a TCP listener while a packet capture is active on the loopback interface.
- Start a listener and capture the appropriate local interface before the client connects.
Mengapa: A trace must include the first handshake packets, not just the application payload.
Hasil yang diharapkan: The first connection can be identified by its 4-tuple of IP addresses and ports.
- Locate SYN from client, SYN+ACK from server, and final ACK from client.
Mengapa: The three messages synchronize TCP sequence spaces.
Hasil yang diharapkan: Flag and relative sequence/ack values form an internally consistent handshake.
- Check the subsequent data or stream event separately.
Mengapa: TCP connection success is not proof an HTTP request was successfully parsed.
Hasil yang diharapkan: The capture shows transport establishment; application handling is a different boundary.
Konsep 2 / 3
Explain TCP stream ordering and distinguish retransmitted segments or transport timeouts from HTTP error responses.
A service may have working application code yet appear slow because transport data requires retransmission before the HTTP request can arrive.
Write why TCP's data sequence number counts bytes rather than HTTP requests.
Intuisi utama
TCP acknowledges byte sequence space, buffers out-of-order data and retransmits unacknowledged bytes; applications receive an ordered byte stream without preserved write/message boundaries.
RFC 9293 describes in-order byte-stream delivery and retransmission. TCP data segments carry sequence ranges; ACK advertises the next expected byte, and duplicate/reordered packets are not new HTTP requests merely because they exist on the wire. RFC 6298 defines RTO from RTT samples and exponential backoff on timeout; packet loss need not trigger an observable retransmission during a short local loopback capture. A transport timeout without a received HTTP response is not an HTTP 408/500. Do not fake a retransmitted packet with an application-level timer or by printing a guessed status.
Contoh bertahap
One packet capture shows an in-order transfer, then a later segment with a previously sent sequence range.
- Compare source/destination 4-tuples and TCP sequence ranges.
Mengapa: A retransmission repeats data sequence space on the same connection.
Hasil yang diharapkan: Match repeated sequence numbers and TCP analysis flags, not only elapsed milliseconds.
- Look for ACK progression and gaps.
Mengapa: Cumulative ACKs identify next expected bytes and can show the consequence of loss/reordering.
Hasil yang diharapkan: Explain whether a new ACK advances after the repeated data is accepted.
- Record whether any HTTP response actually arrived.
Mengapa: Transport delay or timeout is distinct from an application-generated HTTP status.
Hasil yang diharapkan: No HTTP status is claimed if there is no HTTP response message in the trace.
Konsep 3 / 3
Differentiate a normal TCP stream EOF, an abort/reset and connection refusal after a listener stops.
Closing an established stream gracefully and failing to connect at all require different diagnoses and recovery strategies.
Predict whether ECONNREFUSED after listener shutdown is a TCP or HTTP observation.
Intuisi utama
TCP FIN closes one sending direction; RST aborts connection state. A listener that no longer accepts a new connection can produce ECONNREFUSED without an HTTP response.
RFC 9293 §3.6 models normal FIN closing, half-close and RST abort. TIME-WAIT may appear on the active-closer side depending on transition. Node socket.end() and end events expose the stream boundary; they are not proof of a specific FIN/ACK exchange unless correlated with a packet capture. A refused connection after a local server.close() is a failure before application request handling. The fixture verifies connect, payload, peer EOF and subsequent ECONNREFUSED on one loopback port, but never captures on-wire flags, retransmissions or TIME-WAIT. A server close or timeout does not guarantee one exact OS error in every networking environment.
Contoh bertahap
A Node client receives ACK:hello, observes EOF and then cannot reconnect after the listener closes.
- Start a local 127.0.0.1 listener on an ephemeral port.
Mengapa: Avoid external exposure and port collision.
Hasil yang diharapkan: Node connect event reports a successful loopback stream connection.
- Send hello, read ACK:hello and observe stream end.
Mengapa: Payload and EOF are higher-level observations of a connection that carried bytes.
Hasil yang diharapkan: The client sees ACK:hello and end, but no raw FIN flag is exposed by Node.
- Stop the listener and connect to the same local port again.
Mengapa: Contrast a completed connection's close with a new connection refused.
Hasil yang diharapkan: A local ECONNREFUSED is reported after shutdown, not an HTTP 503.
Batas bukti
Fixture Node dalam materi ini membuktikan connected TCP stream, echo payload, peer EOF, dan koneksi baru ditolak setelah listener tutup. Fixture tidak menangkap SYN, ACK, FIN, RST, retransmission, atau TIME-WAIT. Untuk itu gunakan Wireshark/tcpdump di VM/disposable namespace dengan izin akses yang sesuai.
Sumber
Sumber
Cross-domain connections
Curated relationships for this unit at G1. Proposed edges are suggestions, not prerequisites.
Dashed = proposed relationship; solid = reviewed connection. Only reviewed prerequisites constrain a learning path. Keyboard and text links remain available.