R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
IHost Class Referenceabstract

Interface representing a network host (server or client endpoint). More...

#include <IHost.hpp>

Inheritance diagram for IHost:
Inheritance graph
Collaboration diagram for IHost:
Collaboration graph

Public Member Functions

virtual ~IHost ()=default
 
virtual IPeerconnect (const IAddress &address, size_t channelCount=1, uint32_t data=0)=0
 Connect to a remote host.
 
virtual std::optional< HostNetworkEventservice (uint32_t timeout=0)=0
 Service the host, processing network events.
 
virtual void broadcast (std::unique_ptr< IPacket > packet, uint8_t channelID=0)=0
 Broadcast a packet to all connected peers.
 
virtual void flush ()=0
 Send all queued packets immediately.
 
virtual size_t getPeerCount () const =0
 Get the number of connected peers.
 
virtual const IAddressgetAddress () const =0
 Get the address this host is bound to.
 

Detailed Description

Interface representing a network host (server or client endpoint).

IHost manages connections and network communication. It can act as a server accepting connections or as a client connecting to a server. The concrete implementation (ENetHost, custom socket manager, etc.) is hidden behind this interface to allow backend swapping.

Definition at line 49 of file IHost.hpp.

Constructor & Destructor Documentation

◆ ~IHost()

virtual IHost::~IHost ( )
virtualdefault

Member Function Documentation

◆ broadcast()

virtual void IHost::broadcast ( std::unique_ptr< IPacket packet,
uint8_t  channelID = 0 
)
pure virtual

Broadcast a packet to all connected peers.

Parameters
packetThe packet to broadcast.
channelIDThe channel to broadcast on.

Implemented in ENetHostWrapper.

◆ connect()

virtual IPeer * IHost::connect ( const IAddress address,
size_t  channelCount = 1,
uint32_t  data = 0 
)
pure virtual

Connect to a remote host.

Parameters
addressThe address to connect to.
channelCountNumber of channels to allocate (default: 1).
dataUser data to send with the connection request.
Returns
Pointer to the peer object representing the connection, or nullptr on failure.

Implemented in ENetHostWrapper.

◆ flush()

virtual void IHost::flush ( )
pure virtual

Send all queued packets immediately.

Implemented in ENetHostWrapper.

◆ getAddress()

virtual const IAddress & IHost::getAddress ( ) const
pure virtual

Get the address this host is bound to.

Returns
Reference to the host's address.

Implemented in ENetHostWrapper.

◆ getPeerCount()

virtual size_t IHost::getPeerCount ( ) const
pure virtual

Get the number of connected peers.

Returns
Number of connected peers.

Implemented in ENetHostWrapper.

◆ service()

virtual std::optional< HostNetworkEvent > IHost::service ( uint32_t  timeout = 0)
pure virtual

Service the host, processing network events.

Parameters
timeoutMaximum time to wait for events in milliseconds.
Returns
Optional HostNetworkEvent if an event occurred, std::nullopt otherwise.

Implemented in ENetHostWrapper.


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