factorio-rcon
Async RCON client for Factorio with proper multi-packet response handling.
Factorio can return large responses (>64KB) that get fragmented across multiple TCP segments. This crate correctly handles that by reading the length-prefixed packet header first, then using read_exact() to buffer the complete packet body before parsing.
Usage
use RconClient;
use Duration;
async
Prerequisites
Factorio must run as a multiplayer host for RCON to work:
- Launch Factorio
- Multiplayer → Host New Game
- RCON is automatically enabled (check
config.inifor port and password)
Default RCON configuration:
- Port: 27015
- Password: Check
config/config.iniin your Factorio installation
Note: Using /c commands (Lua execution) disables achievements for that save file.
Features
- ✅ Async/await with Tokio
- ✅ Correct multi-packet fragmentation handling
- ✅ Strong error types with thiserror
- ✅ Configurable timeouts
- ✅ Lua execution support with serpent serialization
- ✅ Tracing support for debugging
Error Handling
The crate provides strongly-typed errors for different failure scenarios:
use ;
match connect.await
Testing
Unit tests can be run without a Factorio server:
Integration tests require a running Factorio server and are ignored by default:
# Start Factorio as multiplayer host first
RCON Protocol Details
RCON uses a binary protocol over TCP:
[4 bytes: length] # payload + 10 (excludes this length field)
[4 bytes: request ID] # incremented per command
[4 bytes: type] # 3=auth, 2=command, 0=response
[N bytes: payload] # UTF-8 string
[2 bytes: null term] # 0x00 0x00
All integers are little-endian.
License
MIT OR Apache-2.0