REFERENCE GUIDE

TCP and UDP: delivery, framing, and application state

TCP provides an ordered byte stream; it does not preserve application message boundaries.

Also known as: TCP stream · UDP datagram

tcp-and-udpnetworking

Mechanism

TCP provides an ordered byte stream; it does not preserve application message boundaries. UDP preserves datagram boundaries but does not guarantee delivery or ordering. CTF clients must implement the server protocol rather than assuming one send corresponds to one receive. Timeouts and partial reads are protocol observations, not necessarily server failures.

Practical method

Identify transport, delimiters, length fields, and encoding. Capture a successful exchange if available. Write a client that buffers until a complete application message is present. Log byte lengths and state transitions so dropped datagrams or partial TCP reads are visible.

# A TCP recv may return fewer bytes than the application needs.
chunk = sock.recv(4096)
buffer += chunk

Interpreting evidence

Test with intentionally fragmented writes and multiple messages in one write. A robust parser produces the same application state regardless of TCP segmentation.

Pitfalls and limits

An empty TCP read indicates peer closure. UDP response size and fragmentation can affect reliability. Text decoding should occur after framing to avoid splitting multibyte characters.

Sources & further reading

  1. TCP — RFC 9293 ↗rfc
  2. Socket programming ↗python

Content license: CC-BY-4.0. Source-derived sections retain their cited licenses and redistribution notices. How this reference is compiled →