13 : _port(port), _maxClients(maxClients), _packetHandler(nullptr) {}
38 }
catch (
const std::exception &e) {
49 LOG_INFO(
"Stopping network thread...");
66 while (!stopToken.stop_requested()) {
73 auto eventOpt =
_host->service(1);
88 auto &
event = *eventOpt;
@ RECEIVE
A packet was received.
@ CONNECT
A peer has connected.
@ DISCONNECT
A peer has disconnected.
std::unique_ptr< IAddress > createAddress(const std::string &host, uint16_t port)
Create a network address.
std::unique_ptr< IHost > createServerHost(const IAddress &address, size_t maxClients, size_t channelLimit, uint32_t incomingBandwidth, uint32_t outgoingBandwidth)
Create a host for server-side networking.
~ServerNetworkManager()
Destructor - stops network thread.
std::jthread _networkThread
ServerNetworkManager(uint16_t port, size_t maxClients=32)
Constructor.
ThreadSafeQueue< HostNetworkEvent > _eventQueue
void processMessages()
Process incoming network events from the queue.
std::unique_ptr< IHost > _host
void stop()
Stop the server and network thread.
bool start()
Start the server and network thread.
PacketHandler _packetHandler
void networkThreadLoop(std::stop_token stopToken)
Network thread main loop.
void push(T item)
Push an item to the queue.
std::optional< T > tryPop()
Try to pop an item without blocking.
static void sleepMilliseconds(int milliseconds)
Sleep for specified milliseconds (centralized time management)