Tutorials

Tutorials are guided learning experiences, split into short, numbered pages you follow in order – each links to the next. The first five build one real thing: the frame format for a tiny chat relay, the kind of protocol a small TCP server might speak. The second five apply the same workflow to formats someone else already designed.

Build a chat relay’s frame format

A chat relay forwards short messages between connected clients over TCP. Every message on the wire needs a type tag, a sequence number so drops are detectable, and protection against a corrupted read being mistaken for a valid message. By the end of this sequence you will have defined that frame, packed and decoded it, read it from a socket that delivers bytes in arbitrary chunks, and handled a corrupted frame.

  1. 1. Install rustruct

  2. 2. Define and pack a structure

  3. 3. Decode the message

  4. 4. Try partial input

  5. 5. Inspect an error

Use the bundled protocol and file formats

  1. 1. Decode an IPv4 packet

  2. 2. Build an IPv4 packet with UDP

  3. 3. Build and decode a DNS query

  4. 4. Create a minimal PNG container

  5. 5. Create a transparent 1×1 PNG