Class Engine::Network::UdpServer¶
ClassList > Engine > Network > UdpServer
Multi-threaded high-performance UDP Game Server built on ENet. More...
#include <UdpServer.hpp>
Public Functions¶
| Type | Name |
|---|---|
| void | BroadcastPacket (const uint8_t * data, size_t size, bool reliable=true, uint8_t channel=0) Broadcasts a packet to all connected peers. Thread-safe. |
| void | BroadcastPacket (const ByteWriter & writer, bool reliable=true, uint8_t channel=0) |
| void | DisconnectPeer (ENetPeer * peer, uint32_t data=0) Disconnects a specific peer cleanly. |
| size_t | GetConnectedCount () const |
| uint16_t | GetPort () noexcept const |
| bool | IsRunning () noexcept const |
| void | PollEvents (const std::function< void(const NetworkEvent &)> & handler) Drains all queued incoming network events from the I/O thread to the main thread. |
| void | SendPacket (ENetPeer * peer, const uint8_t * data, size_t size, bool reliable=true, uint8_t channel=0) Sends a packet to a specific connected peer. Thread-safe. |
| void | SendPacket (ENetPeer * peer, const ByteWriter & writer, bool reliable=true, uint8_t channel=0) |
| bool | Start (uint16_t port, size_t maxClients=32, size_t channels=2, bool multiThreaded=true) Starts the UDP server on the specified port. |
| void | Stop () Stops the server, disconnects all peers, and joins the I/O thread. |
| UdpServer () |
|
| UdpServer (const UdpServer &) = delete |
|
| UdpServer & | operator= (const UdpServer &) = delete |
| virtual | ~UdpServer () |
Protected Attributes¶
| Type | Name |
|---|---|
| std::queue< NetworkEvent > | incomingEvents_ |
| std::thread | ioThread_ |
| std::atomic< bool > | isRunning_ = {false} |
| bool | multiThreaded_ = {true} |
| uint16_t | port_ = {0} |
| std::mutex | queueMutex_ |
| std::mutex | sendMutex_ |
| ENetHost * | serverHost_ = {nullptr} |
Protected Functions¶
| Type | Name |
|---|---|
| void | NetworkIoLoop () |
| void | ProcessEnetEvents () |
Detailed Description¶
Runs network I/O asynchronously on a dedicated worker thread, buffering network events in a thread-safe queue. The game simulation loop can poll events without ever blocking frame execution or risking packet loss.
Public Functions Documentation¶
function BroadcastPacket [½]¶
Broadcasts a packet to all connected peers. Thread-safe.
void Engine::Network::UdpServer::BroadcastPacket (
const uint8_t * data,
size_t size,
bool reliable=true,
uint8_t channel=0
)
function BroadcastPacket [2/2]¶
void Engine::Network::UdpServer::BroadcastPacket (
const ByteWriter & writer,
bool reliable=true,
uint8_t channel=0
)
function DisconnectPeer¶
Disconnects a specific peer cleanly.
function GetConnectedCount¶
function GetPort¶
function IsRunning¶
function PollEvents¶
Drains all queued incoming network events from the I/O thread to the main thread.
void Engine::Network::UdpServer::PollEvents (
const std::function< void(const NetworkEvent &)> & handler
)
Parameters:
handlerCallback invoked for each received event.
function SendPacket [½]¶
Sends a packet to a specific connected peer. Thread-safe.
void Engine::Network::UdpServer::SendPacket (
ENetPeer * peer,
const uint8_t * data,
size_t size,
bool reliable=true,
uint8_t channel=0
)
function SendPacket [2/2]¶
void Engine::Network::UdpServer::SendPacket (
ENetPeer * peer,
const ByteWriter & writer,
bool reliable=true,
uint8_t channel=0
)
function Start¶
Starts the UDP server on the specified port.
bool Engine::Network::UdpServer::Start (
uint16_t port,
size_t maxClients=32,
size_t channels=2,
bool multiThreaded=true
)
Parameters:
portUDP port to listen on.maxClientsMaximum concurrent client connections.channelsNumber of ENet channels.multiThreadedWhen true, spawns a background I/O thread for network polling.
Returns:
True if bind and startup succeeded.
function Stop¶
Stops the server, disconnects all peers, and joins the I/O thread.
function UdpServer [½]¶
function UdpServer [2/2]¶
function operator=¶
function ~UdpServer¶
Protected Attributes Documentation¶
variable incomingEvents_¶
variable ioThread_¶
variable isRunning_¶
variable multiThreaded_¶
variable port_¶
variable queueMutex_¶
variable sendMutex_¶
variable serverHost_¶
Protected Functions Documentation¶
function NetworkIoLoop¶
function ProcessEnetEvents¶
The documentation for this class was generated from the following file /home/runner/work/r-type/r-type/Engine/include/Network/UdpServer.hpp