High-level ENet-based server host for handling multiple client connections, broadcasting messages, and routing incoming packets.
More...
#include <host.h>
|
| | Host (std::reference_wrapper< Router > router, int connection_port, int max_clients) |
| | Constructs the Host with a Router, target port, and maximum number of clients.
|
| |
| | ~Host () noexcept |
| | Destructs the Host and releases ENet resources safely.
|
| |
| void | start_server () |
| | Starts the ENet server.
|
| |
| void | poll () noexcept |
| | Polls ENet for incoming events (connect/disconnect/receive). Forwards packets through the Router.
|
| |
| void | broadcast (const Message &message) noexcept |
| | Broadcasts a message to all connected peers.
|
| |
| void | disconnect () noexcept |
| | Disconnects all clients and destroys the ENet server.
|
| |
| ConnectionState | get_connection_state () const noexcept |
| | Returns the current server connection state.
|
| |
| std::string | get_uuid () const noexcept |
| |
| void | set_max_clients (int amount) noexcept |
| | Sets the maximum number of clients allowed.
|
| |
| int | get_client_amount () const noexcept |
| | Returns the number of currently connected clients.
|
| |
| std::string | get_ip () const noexcept |
| |
| void | set_connection_port (int port) noexcept |
| | Sets the server port. Only effective before start_server().
|
| |
| void | send_to_peer_via_uuid (const std::string &uuid, const Message &message) noexcept |
| | Sends a message to a connected client identified by UUID.
|
| |
| void | sync () noexcept |
| | Broadcasts delta snapshots of the scene to all connected clients.
|
| |
High-level ENet-based server host for handling multiple client connections, broadcasting messages, and routing incoming packets.
The Host object owns its ENetHost and manages the lifecycle of all connected clients. It interacts with the Router to forward incoming messages to application-defined handlers.
◆ Host()
| Host::Host |
( |
std::reference_wrapper< Router > |
router, |
|
|
int |
connection_port, |
|
|
int |
max_clients |
|
) |
| |
Constructs the Host with a Router, target port, and maximum number of clients.
- Parameters
-
| router | Shared pointer to message routing system. |
| connection_port | Port on which to listen for incoming clients. |
| max_clients | Maximum number of simultaneous connections allowed. |
◆ ~Host()
Destructs the Host and releases ENet resources safely.
◆ broadcast()
| void Host::broadcast |
( |
const Message & |
message | ) |
|
|
noexcept |
Broadcasts a message to all connected peers.
- Parameters
-
◆ disconnect()
| void Host::disconnect |
( |
| ) |
|
|
noexcept |
Disconnects all clients and destroys the ENet server.
◆ get_client_amount()
| int Host::get_client_amount |
( |
| ) |
const |
|
noexcept |
Returns the number of currently connected clients.
◆ get_connection_state()
Returns the current server connection state.
◆ get_ip()
| std::string Host::get_ip |
( |
| ) |
const |
|
noexcept |
◆ get_uuid()
| std::string Host::get_uuid |
( |
| ) |
const |
|
noexcept |
◆ poll()
Polls ENet for incoming events (connect/disconnect/receive). Forwards packets through the Router.
◆ send_to_peer_via_uuid()
| void Host::send_to_peer_via_uuid |
( |
const std::string & |
uuid, |
|
|
const Message & |
message |
|
) |
| |
|
noexcept |
Sends a message to a connected client identified by UUID.
- Parameters
-
| uuid | Target client's UUID. |
| message | Message to send. |
◆ set_connection_port()
| void Host::set_connection_port |
( |
int |
port | ) |
|
|
noexcept |
◆ set_max_clients()
| void Host::set_max_clients |
( |
int |
amount | ) |
|
|
noexcept |
Sets the maximum number of clients allowed.
◆ start_server()
| void Host::start_server |
( |
| ) |
|
Starts the ENet server.
- Exceptions
-
| std::runtime_error | if ENet fails to create a server host. |
◆ sync()
Broadcasts delta snapshots of the scene to all connected clients.
The documentation for this class was generated from the following file: