#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. | |
| 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.
The ServerPP generates the public.key and private.key files when they are not given.
| address | Address used for the server's creation. |
| port | Port used for the server's creation. |
| separator | Separator used during this session. |
| ipType | IP type used by this server (IPv4 or IPv6) (default : IP_Type::IPv4) |
| useCiphering | Tells the server if you want to use ciphering or not (default : true) |
| publicKeyFile | If different from "", force the use of the given public key. |
| privateKeyFile | If different from "", force the use of the given private key. |
| ServerPP::~ServerPP | ( | ) |
Destructor of the ServerPP class.
| std::vector< std::string > ServerPP::getChannelKeys | ( | ) |
Return a list which contains every plugged channel's keys.
| 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.
| clientID | Client's ID on the server. |
| void ServerPP::plug | ( | std::shared_ptr< Channel > | channel, |
| ChannelType | type ) |
Plug a new channel to the server and start it in a jthread.
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.
| channel | A shared_ptr to the channel to plug. |
| type | The channel type (GLOBAL, METADATA, DATA or/and SLEEPING) |
| void ServerPP::setChannelState | ( | const std::string & | key, |
| const ChannelState & | state ) |
| 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.
| 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.
| 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.
| key | The key of the Channel to unplug. |