NSCpp 2.0
NSCpp is a modern C++20 server/client framework designed to simplify network programming in C++. With robust support for both IPv4 and IPv6, as well as TCP and UDP communication protocols.
 
Loading...
Searching...
No Matches
ServerPP Class Reference

#include <ServerPP.h>

Public Member Functions

 ServerPP (std::string address, int port, std::string separator, IP_Type ipType=IP_Type::IPv4, bool useCiphering=true, const std::string &publicKeyFile="", const std::string &privateKeyFile="")
 Constructor of the ServerPP.
 
 ~ServerPP ()
 Destructor of the ServerPP class.
 
void start ()
 Create the servers (TCP and UDP) with the given parameters and start the run method.
 
void stop ()
 Stop the server, disconnect properly every clients and clear everything.
 
void plug (std::shared_ptr< Channel > channel, ChannelType type)
 Plug a new channel to the server and start it in a jthread.
 
void unplug (const std::string &key)
 Unplug a channel based on its key.
 
std::vector< std::string > getChannelKeys ()
 Return a list which contains every plugged channel's keys.
 
void setChannelState (const std::string &key, const ChannelState &state)
 Update a channel state through the server.
 
void kicked (const std::string &clientID)
 Callback used to tell the server you kicked a client.
 

Constructor & Destructor Documentation

◆ ServerPP()

ServerPP::ServerPP ( std::string address,
int port,
std::string separator,
IP_Type ipType = IP_Type::IPv4,
bool useCiphering = true,
const std::string & publicKeyFile = "",
const std::string & privateKeyFile = "" )

Constructor of the ServerPP.

Warning
The given Public and Private keys should be valid, and you have to give both of them at the same time.

The ServerPP generates the public.key and private.key files when they are not given.

Parameters
addressAddress used for the server's creation.
portPort used for the server's creation.
separatorSeparator used during this session.
ipTypeIP type used by this server (IPv4 or IPv6) (default : IP_Type::IPv4)
useCipheringTells the server if you want to use ciphering or not (default : true)
publicKeyFileIf different from "", force the use of the given public key.
privateKeyFileIf different from "", force the use of the given private key.

◆ ~ServerPP()

ServerPP::~ServerPP ( )

Destructor of the ServerPP class.

Member Function Documentation

◆ getChannelKeys()

std::vector< std::string > ServerPP::getChannelKeys ( )

Return a list which contains every plugged channel's keys.

◆ kicked()

void ServerPP::kicked ( const std::string & clientID)

Callback used to tell the server you kicked a client.

You can notify through the "Kick" group that you have kicked a client and this callback will removed it from the server.

See also
Automatically used by the Client::kick method.
Parameters
clientIDClient's ID on the server.

◆ plug()

void ServerPP::plug ( std::shared_ptr< Channel > channel,
ChannelType type )

Plug a new channel to the server and start it in a jthread.

Warning
The Channel's key should be unique, otherwise a Channel with the same key as another one will replace it.

This newly plugged channel will received informations based on its type.

The Channel's types are : GLOBAL, METADATA, DATA and SLEEPING and can be combine with the | operator.

METADATA : Information about Connection and Disconnection events.

GLOBAL : Every DataReceived events are redirected to these channels.

DATA : Only DataReceived events prefixed by the channel's key are redirected to them.

Sleeping : No data is send to this channel by the server but it is started and can be used by other channels.

Parameters
channelA shared_ptr to the channel to plug.
typeThe channel type (GLOBAL, METADATA, DATA or/and SLEEPING)

◆ setChannelState()

void ServerPP::setChannelState ( const std::string & key,
const ChannelState & state )

Update a channel state through the server.

States could be ACTIVE or INACTIVE

An INACTIVE channels will not received any data.

Parameters
keyChannel's key.
stateChannel's new state.

◆ start()

void ServerPP::start ( )

Create the servers (TCP and UDP) with the given parameters and start the run method.

Run method is started in a jthread.

◆ stop()

void ServerPP::stop ( )

Stop the server, disconnect properly every clients and clear everything.

The run thread is join before the clearing so everything can stop properly without crashes.

◆ unplug()

void ServerPP::unplug ( const std::string & key)

Unplug a channel based on its key.

Every channel should have a specific and unique key to be identified.

The channel's thread will be stopped.

Parameters
keyThe key of the Channel to unplug.

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