cnet::Server is a threaded async udp and tcp communication server implemented for you
class Server
{
public:
OnReceiveEvent OnReceive;
OnConnectedEvent OnClientConnected;
OnDisconnectedEvent OnClientDisconnected;
private:
std::vector<Address> clients;
std::unordered_map<Address, std::shared_ptr<Socket>> addressToClient;
bool running = false;
std::shared_ptr<TCPSocket> tcpSocket;
std::shared_ptr<UDPSocket> udpSocket;
std::thread tcpThread;
std::thread udpThread;
};
| Name | Description | Return type |
|---|---|---|
| Run | Starts the server | void |
| IsRunning | Returns whether the server is running | bool |
| Close | Closes the server and cleans up | void |
| CloseClient | Closes the client with the specified address | void |
| SendAll | Send data to all connected clients | bool |
| Send | Send data to a specific client | bool |
| IsClientConnected | Returns whether a specific client is connected | bool |
| GetPeerAddress | Returns the peer address of the server | cnet::Address |
| GetSockAddress | Returns the server's address | cnet::Address |
| GetClients | Returns a vector containing all the clients addresses | std::vector<cnet::Address> |