A small educational networked CLI project written in pure C, demonstrating an event-driven model of client interaction through a relay server with Master-Client Authority.
The project was created as a practical exercise in:
- network programming in C,
- working with ENet (UDP + reliable delivery),
- message serialization and deserialization using MsgPack,
- multithreading and synchronization,
- designing client ↔ server architecture without a real-time loop.
- There is a relay server that contains no game logic
- The first connected client becomes the Master
- The Master:
- stores the world state
- processes input from other clients
- broadcasts the updated state to all clients
- Other clients (Slaves):
- send only their input commands
- apply the state received from the Master
The model is not real-time, but event-driven:
- the world is updated via the
tickcommand - ideal for learning, debugging, and understanding networking patterns
Key principles:
- the server does not interpret data
- the server only relays messages
- all logic is concentrated in the Master client
- a single shared message protocol for both client and server
.
├── Makefile
├── README.md
└── src
├── client.c # CLI client (Master / Slave)
├── server.c # Relay server
├── protocol_msg.h # Shared network protocol
├── help_func/ # Helper functions
└── thread_safe/ # Thread-safe structures
- C (C17)
- ENet — UDP networking library with reliable delivery
- MsgPack-C — binary message serialization
- POSIX Threads (pthreads) — multithreading
- Linux / WSL2
The project targets Unix-like systems.
All messages are defined in protocol_msg.h.
Examples of message types:
- client registration
- Master assignment
- client input (intention to change state)
- world state snapshot
Serialization is performed using MsgPack, which:
- removes the need for manual framing
- makes the protocol extensible
- allows using identical structures on both client and server
- The ENet networking loop runs in a dedicated thread
- CLI input is handled independently
- Inter-thread communication is implemented via thread-safe queues
- Race conditions when working with ENet are eliminated
Install required libraries:
sudo apt install libenet-dev libmsgpack-devmakeThis will produce:
serverclient
./server./client <server_ip>You can run:
- multiple clients on the same machine
- clients on different machines within the same LAN / Wi-Fi network
Example client commands:
tick
x+
x-
y+
y-
tick— triggers a world update (Master only)- other commands send input to the Master client
This project was created not as a game, but as:
-
an educational sandbox for network programming
-
a foundation for transitioning to:
- real-time synchronization
- prediction / reconciliation
- an authoritative server model
-
source material for articles and educational content
