⚡ Zig Guide LiveUnofficialbut fully verified
✓ Zig 0.17.0-dev.1503+1f1bee62eOn an older Zig?

Networking

Sockets from the beginning, then the part that actually decides whether a server works: a stream has no message boundaries, so you put them back yourself. Framing three ways, a parser that survives a message split across two reads, text and binary protocols in both directions, byte order, and one handler per connection through the Io interface. The protocol chapters run in your browser, because none of them know what a socket is.

  1. TCP is a byte stream, not a message stream. A read returning 7 bytes says nothing about where a message ends, and code that assumes otherwise works until it meets a real network.
  2. Parse from a Reader, never from a socket. The same parser then works over a connection, over a test fixture and in a browser, and you write it once.
  3. State the byte order at every call, and never send a struct. Padding is not yours to define and the layout is whatever your compiler chose today.
  4. takeDelimiterExclusive treats end of stream as a delimiter, so a client that dies mid-message hands you a fragment that looks like a complete one.
  5. io.async and Group replaced the removed async/await keywords. The same source serves connections on a thread pool or inline, and the caller picks.

10 chapters.