Skip to content

Network

Tom Colas edited this page Jan 18, 2026 · 1 revision

Network Core Library

Overview

network.hpp contains the low-level networking primitives shared by both client and server. It defines packet structures, headers, SAFE packet tracking, and the packet_handler.


Packet Format

Header (net::Header)

Field Type Description
id size_t Message / entity identifier
protocol uint16_t BASIC or SAFE
safeUid uint16_t SAFE acknowledgment ID
size uint16_t Payload size
type uint16_t Message type

Packet (net::Packet)

struct Packet {
    Header header;
    const void *data;
};

SAFE Protocol Internals

PendingPackets

Tracks unacknowledged SAFE packets.

std::unordered_map<
    int, std::unordered_map<int, SafePacket>
>

Retransmission

  • Timeout: TIME_OUT (default: 100ms)
  • Retransmission continues until ACK is received
  • Automatic cancellation on client disconnect

packet_handler

Responsible for:

  • Packet serialization
  • Sending packets
  • SAFE retransmission scheduling
  • ACK handling

Constants

Name Value
TIME_OUT 100 ms
DEFAULT_SAFE_UID 0
Max Packet Size 1024 bytes

Design Philosophy

  • UDP-first architecture
  • Explicit reliability when needed
  • Minimal overhead for real-time gameplay

Clone this wiki locally