Project 8: Network Protocol with bit_sets

A custom binary network protocol for a multiplayer game or chat application, using Odin’s bit_sets for flags, distinct types for message IDs, and unions for message payloads.

Quick Reference

Attribute Value
Primary Language Odin
Alternative Languages C, Rust
Difficulty Level 3: Advanced
Time Estimate 2 weeks
Knowledge Area Networking / Binary Protocols
Tooling Odin’s core:net
Prerequisites Basic networking concepts, Project 3 (JSON Parser for unions)

What You Will Build

A custom binary network protocol for a multiplayer game or chat application, using Odin’s bit_sets for flags, distinct types for message IDs, and unions for message payloads.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Binary serialization with exact layouts → maps to struct packing and #packed
  • Message type discrimination → maps to tagged unions for protocols
  • Flags and bitfields → maps to bit_set for protocol flags
  • Non-blocking I/O → maps to Odin’s socket API

Key Concepts

Real-World Outcome

$ odin run server &
[Server] Listening on 0.0.0.0:7777

$ odin run client
[Client] Connected to localhost:7777

# Client terminal:
> /join general
[Server] Joined channel: general (5 users)

> Hello everyone!
[You] Hello everyone!
[Bob] Hey! Welcome!
[Alice] o/

> /dm Alice Hey, want to play?
[DM to Alice] Hey, want to play?
[DM from Alice] Sure! Let's go

> /status playing
[Server] Status updated to: playing

# Protocol analysis (wireshark):
Packet: 12 bytes
  Header (4 bytes):
    Magic: 0x4F44 ("OD")
    Flags: [Compressed, Encrypted]
    Seq: 42
  Payload (8 bytes):
    MsgType: ChatMessage (0x03)
    Channel: 1
    Length: 15
    Content: "Hello everyone!"

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: LEARN_ODIN_PROGRAMMING_LANGUAGE.md
  • “TCP/IP Illustrated, Volume 1” by W. Richard Stevens