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

  1. UDP server binds to the configured port
  2. Each incoming datagram is identified by the sender's IP:Port
  3. A stable clientId is generated using MurmurHash3 of the sender's address
  4. Packets are decoded and routed to [Gate] handlers
  5. "Connection" is activity-based — a client is considered connected while it has recent activity (30-minute timeout)

Key Differences from TCP/WebSocket

AspectWebSocket/TCPUDP
ReliabilityOrdered, reliable deliveryBest-effort, may lose packets
ConnectionExplicit connect/disconnectActivity-based (connectionless)
OverheadHigher (handshake, framing)Minimal (raw datagrams)
Use caseChat, login, inventoryPosition 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.