Demonstrating core techniques for responsive, cheat-resistant multiplayer games in Rust.
A networked multiplayer demo built in Rust showcasing server-authoritative architecture with client-side prediction, server reconciliation, entity interpolation, and lag compensation. Built to demonstrate the core netcode techniques behind responsive, cheat-resistant multiplayer games.
- Server Authority — The server is the single source of truth; clients cannot manipulate game state directly.
- Client-Side Prediction — Inputs are applied locally and immediately for zero-latency-feeling movement.
- Server Reconciliation — Clients replay unacknowledged inputs after receiving authoritative state, correcting drift smoothly.
- Entity Interpolation — Remote players are rendered in the past and interpolated between snapshots for smooth motion.
- Lag Compensation — Hit detection rewinds the world to the shooter's view at the time of fire.
- Snapshot Compression & Delta Encoding — Only changed state is transmitted to minimize bandwidth.
- Configurable Network Conditions — Built-in simulated latency, jitter, and packet loss for testing.
┌─────────────┐ UDP ┌─────────────┐
│ Client A │◄────────────────────►│ │
└─────────────┘ inputs / snapshots│ │
│ Server │
┌─────────────┐ │ (authority) │
│ Client B │◄────────────────────►│ │
└─────────────┘ └─────────────┘
- Client sends timestamped input commands and predicts the result locally.
- Server processes inputs at a fixed tick rate, simulates the authoritative world, and broadcasts snapshots.
- Reconciliation occurs when a client receives a snapshot: it discards acknowledged inputs and replays the rest.
| Component | Rate |
|---|---|
| Server simulation | 60 Hz |
| Snapshot send | 20 Hz |
| Client render | Uncapped |
- Language: Rust (2021 edition)
- Networking:
tokio+ UDP sockets - Serialization:
bincode/serde - Rendering (client):
macroquad - Math:
glam
- Rust 1.75+ (install via rustup)
git clone https://github.com/zuedev/rust-authoritative-netcode-demo.git
cd rust-authoritative-netcode-demo
cargo build --releasecargo run --release --bin server -- --port 7777 --tick-rate 60cargo run --release --bin client -- --connect 127.0.0.1:7777Launch multiple clients to see prediction and interpolation in action.
| Key | Action |
|---|---|
WASD |
Move |
Mouse |
Aim |
Click |
Fire |
F3 |
Toggle netgraph |
Esc |
Quit |
Press F3 in the client to display the netgraph overlay, which shows:
- Round-trip time (RTT) and jitter
- Prediction error / reconciliation corrections
- Interpolation buffer state
- Packet loss percentage
cargo run --release --bin client -- --connect 127.0.0.1:7777 --sim-latency 100 --sim-jitter 20 --sim-loss 0.05Run the full unit-test suite — covering the wire protocol and delta encoding, the deterministic simulation, server input handling and lag compensation, and client prediction / reconciliation / interpolation:
cargo test --workspaceFor an end-to-end check without opening a window, run the headless smoke test in a second terminal while the server is running. It connects, drives a player, and asserts that the authoritative server moves it and emits delta snapshots:
# terminal 1
cargo run --bin server
# terminal 2
cargo run -p client --example headless_smokeThe performance-critical paths — the deterministic simulation step, hitscan ray
casts, and delta snapshot encoding / decoding — are benchmarked with
criterion:
cargo bench -p shared.
├── crates/
│ ├── shared/ # Types, protocol, deterministic simulation (unit tests + benches)
│ ├── server/ # Authoritative server binary (unit tests)
│ └── client/ # Predicting client binary (unit tests + headless example)
└── Cargo.toml # Workspace manifest
This project draws on well-known netcode resources: