Client
The Client class store all networking information about a client
Public member functions
//Construct a new client
Client(asio::ip::udp::socket &socket, asio::ip::udp::endpoint endpoint);
//Destruct a client
~Client();
Client(const Client &client) = delete;
Client(Client &&client) = delete;
Client &operator=(const Client &client) = delete;
Client &operator=(Client &&client) = delete;
//get the client endpoint
const asio::ip::udp::endpoint &getEndpoint() const;
//get all the incomming client data before being packaged
Stream &getStreamIn();
//return an instruction and a stream if a package is avaible in _streamIn
std::pair<size_t, Stream> getNextInst();
//get the out binary buffer in preparation
Stream &getStreamOut();
//set an instruction before sending
void setInst(unsigned char inst);
//send a Stream to this client
void send(const Stream &message);
//send the Stream _streamOut with the _instOut
void send();
//check last time client exchange with the server
bool isAlive();
//update the client activity
void ping();
Private attributes
asio::ip::udp::socket &_socket;
asio::ip::udp::endpoint _endpoint;
Stream _streamIn;
Stream _streamOut;
unsigned char _instOut;
size_t _lastActivity;
std::chrono::system_clock::time_point _lastPing = std::chrono::system_clock::now();
Member functions documentation
Constructor
Client(asio::ip::udp::socket &socket, asio::ip::udp::endpoint endpoint);
Parameters
socket
the server socketendpoint
the client endpoint
getEndpoint
return the client endpoint
const asio::ip::udp::endpoint &getEndpoint() const;
getStreamIn
return the incomming stream
Stream &getStreamIn();
getNextInst
Try to get an instruction from th _streamIn. If it can, it return the instruction and the stream of request.
std::pair<size_t, Stream> getNextInst();
getStreamOut
return the _outStream attribute
Stream &getStreamOut();
setInst
Set the _instOut attribute
void setInst(unsigned char inst);
send
send the Stream in parameter to the client
void send(const Stream &message);
send
send the _streamOut stream with the _instOut instruction
void send();
isAlive
check the time since the last client activity
bool isAlive();
ping
refresh th client activity
void ping();
Last updated