-
Notifications
You must be signed in to change notification settings - Fork 0
Network Server API
Tom Colas edited this page Jan 18, 2026
·
2 revisions
The server class provides an asynchronous UDP server with built-in reliable packet handling (SAFE protocol).
It manages connected clients, message dispatching, and acknowledgment logic.
Designed for multiplayer game servers using ECS-based architectures.
- Fully UDP-based server
- TCP-like reliability layer (SAFE)
- Client auto-discovery
- Thread-safe message queue
- Broadcast and selective messaging
server(short port);Creates and binds a UDP server.
-
port– UDP port to listen on
std::atomic_bool running;Indicates whether the server is currently running.
void send(
const std::string &client,
size_t id,
uint16_t protocol,
uint16_t type,
uint16_t size,
const void *data,
uint16_t uid = 0
);Sends a packet to a specific client.
void sendAll(
size_t id,
uint16_t protocol,
uint16_t type,
uint16_t size,
const void *data
);Broadcasts a packet to all connected clients.
void sendAllExcept(
const std::string &clientToExcept,
size_t id,
uint16_t protocol,
uint16_t type,
uint16_t size,
const void *data
);Broadcasts a packet to all clients except one.
void pushMessage(
size_t id,
uint16_t protocol,
uint16_t type,
uint16_t size,
const void *data
);Queues a packet for later broadcast.
void sendMessages();Flushes the send queue and dispatches all queued packets.
bool popMessage(std::pair<std::string, data> &out);Retrieves a received message.
-
trueif a message was available -
falseotherwise
void removeClient(std::string &client);
void clear();
void allowNewClient(bool enable);
size_t size() const;Clients are identified using:
<ip>:<port>
Each client is assigned a unique SAFE UDP ID internally.
- One dedicated network thread
- Message queues protected by mutex
- Asynchronous I/O using Boost.Asio
server srv(8080);
while (srv.running) {
std::pair<std::string, data> msg;
while (srv.popMessage(msg)) {
// Process message
}
}- SAFE packets are retransmitted until acknowledged
- Client connections are stateless (UDP-based)
- Max packet size: 1024 bytes