UDP Transport
UDP transport provides fast, connectionless communication — ideal for real-time game data where occasional packet loss is acceptable (e.g., position updates).
Configuration
altruist:
server:
http:
host: "0.0.0.0"
port: 8080
transport:
codec:
provider: messagepack
udp:
enabled: true
port: 13001
Note:
UDP is often used alongside TCP — TCP for reliable operations (login, inventory, chat) and UDP for fast updates (movement, combat). See Server Setup for multi-transport configuration.
How It Works
- UDP server binds to the configured port
- Each incoming datagram is identified by the sender's
IP:Port - A stable
clientIdis generated using MurmurHash3 of the sender's address - Packets are decoded and routed to
[Gate]handlers - "Connection" is activity-based — a client is considered connected while it has recent activity (30-minute timeout)
Key Differences from TCP/WebSocket
| Aspect | WebSocket/TCP | UDP |
|---|---|---|
| Reliability | Ordered, reliable delivery | Best-effort, may lose packets |
| Connection | Explicit connect/disconnect | Activity-based (connectionless) |
| Overhead | Higher (handshake, framing) | Minimal (raw datagrams) |
| Use case | Chat, login, inventory | Position sync, fast updates |
Portal Code is Identical
[Portal("/game")]
public class PositionPortal : Portal
{
[Gate("move")]
public async Task OnMove(MovePacket packet, string clientId)
{
// Same portal code works for UDP
await _router.Broadcast.SendAsync(packet, excludeClientId: clientId);
}
}
Note:
UDP is connectionless — there is no explicit disconnect event. The framework considers a UDP client "disconnected" after 30 minutes of inactivity.