Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
Client Class Reference

High-level ENet-based network client. Handles connecting, disconnecting, sending messages, and routing received messages. More...

#include <client.h>

Public Member Functions

 Client (std::reference_wrapper< Router > router)
 Construct a Client with a shared Router.
 
 ~Client () noexcept
 Safely destroys the client, unregisters handlers and frees ENet resources.
 
void poll () noexcept
 Polls the network for incoming ENet events. Routes received messages and updates connection state.
 
void send (const Message &message) noexcept
 Sends a message to the connected server peer.
 
void connect (const std::string &host_ip, int connection_port)
 Initiates connection to a remote host.
 
void disconnect () noexcept
 Begins a clean disconnect by sending a disconnect message.
 
ConnectionState get_connection_state () const noexcept
 Returns current connection state.
 
std::string get_uuid () const noexcept
 
std::string get_host_ip () const noexcept
 

Detailed Description

High-level ENet-based network client. Handles connecting, disconnecting, sending messages, and routing received messages.

The Client owns its ENetHost and manages lifecycle events. Incoming messages are forwarded through the Router for user-defined handling.

Constructor & Destructor Documentation

◆ Client()

Client::Client ( std::reference_wrapper< Router router)
explicit

Construct a Client with a shared Router.

Parameters
routerPointer to router used for dispatching messages.
Exceptions
std::runtime_errorif ENet client host creation fails.

◆ ~Client()

Client::~Client ( )
noexcept

Safely destroys the client, unregisters handlers and frees ENet resources.

Member Function Documentation

◆ connect()

void Client::connect ( const std::string &  host_ip,
int  connection_port 
)

Initiates connection to a remote host.

Parameters
host_ipTarget IPv4/IPv6 address.
connection_portTarget port.
Exceptions
std::runtime_errorif ENet cannot allocate a peer.

◆ disconnect()

void Client::disconnect ( )
noexcept

Begins a clean disconnect by sending a disconnect message.

◆ get_connection_state()

ConnectionState Client::get_connection_state ( ) const
noexcept

Returns current connection state.

◆ get_host_ip()

std::string Client::get_host_ip ( ) const
noexcept

◆ get_uuid()

std::string Client::get_uuid ( ) const
noexcept

◆ poll()

void Client::poll ( )
noexcept

Polls the network for incoming ENet events. Routes received messages and updates connection state.

◆ send()

void Client::send ( const Message message)
noexcept

Sends a message to the connected server peer.

Parameters
messageMessage to send.

The documentation for this class was generated from the following file: