R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
NetworkFactory.hpp File Reference
#include <cstdint>
#include <memory>
#include "IAddress.hpp"
#include "IHost.hpp"
#include "IPacket.hpp"
Include dependency graph for NetworkFactory.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::unique_ptr< IHostcreateServerHost (const IAddress &address, size_t maxClients=32, size_t channelLimit=2, uint32_t incomingBandwidth=0, uint32_t outgoingBandwidth=0)
 Create a host for server-side networking.
 
std::unique_ptr< IHostcreateClientHost (size_t channelLimit=2, uint32_t incomingBandwidth=0, uint32_t outgoingBandwidth=0)
 Create a host for client-side networking.
 
std::unique_ptr< IPacketcreatePacket (const std::vector< uint8_t > &data, uint32_t flags=static_cast< uint32_t >(PacketFlag::RELIABLE))
 Create a network packet with the given data and flags.
 
std::unique_ptr< IAddresscreateAddress (const std::string &host="0.0.0.0", uint16_t port=0)
 Create a network address.
 
bool initializeNetworking ()
 Initialize the networking subsystem.
 
void deinitializeNetworking ()
 Cleanup the networking subsystem.
 

Function Documentation

◆ createAddress()

std::unique_ptr< IAddress > createAddress ( const std::string &  host = "0.0.0.0",
uint16_t  port = 0 
)

Create a network address.

Parameters
hostThe hostname or IP address.
portThe port number.
Returns
Unique pointer to an IAddress instance.

Definition at line 37 of file NetworkFactory.cpp.

Referenced by Replicator::connect(), and ServerNetworkManager::start().

◆ createClientHost()

std::unique_ptr< IHost > createClientHost ( size_t  channelLimit = 2,
uint32_t  incomingBandwidth = 0,
uint32_t  outgoingBandwidth = 0 
)

Create a host for client-side networking.

This function creates a host that can initiate connections to servers. The concrete implementation (ENet, custom backend) is hidden from the caller.

Parameters
channelLimitMaximum number of channels per connection.
incomingBandwidthIncoming bandwidth limit (0 = unlimited).
outgoingBandwidthOutgoing bandwidth limit (0 = unlimited).
Returns
Unique pointer to an IHost instance configured as a client.

Definition at line 28 of file NetworkFactory.cpp.

◆ createPacket()

std::unique_ptr< IPacket > createPacket ( const std::vector< uint8_t > &  data,
uint32_t  flags = static_cast< uint32_t >(PacketFlag::RELIABLE) 
)

◆ createServerHost()

std::unique_ptr< IHost > createServerHost ( const IAddress address,
size_t  maxClients = 32,
size_t  channelLimit = 2,
uint32_t  incomingBandwidth = 0,
uint32_t  outgoingBandwidth = 0 
)

Create a host for server-side networking.

This function creates a host that listens for incoming connections on the specified address. The concrete implementation (ENet, custom backend) is hidden from the caller.

Parameters
addressAddress to bind the server to.
maxClientsMaximum number of clients that can connect.
channelLimitMaximum number of channels per connection.
incomingBandwidthIncoming bandwidth limit (0 = unlimited).
outgoingBandwidthOutgoing bandwidth limit (0 = unlimited).
Returns
Unique pointer to an IHost instance configured as a server.

Definition at line 22 of file NetworkFactory.cpp.

Referenced by ServerNetworkManager::start().

◆ deinitializeNetworking()

void deinitializeNetworking ( )

Cleanup the networking subsystem.

Should be called when networking is no longer needed.

Definition at line 18 of file NetworkFactory.cpp.

Referenced by Client::~Client(), and Server::~Server().

◆ initializeNetworking()

bool initializeNetworking ( )

Initialize the networking subsystem.

Must be called before using any networking functions.

Returns
True if initialization succeeded, false otherwise.

Definition at line 14 of file NetworkFactory.cpp.

Referenced by Client::initialize(), and Server::initialize().