VOX
A little voxel engine
Loading...
Searching...
No Matches
Client Class Reference

The Client side interface with the network module. More...

#include <Client.hpp>

Collaboration diagram for Client:
Collaboration graph

Classes

struct  sendInfo
 
class  ServerDisconnected
 

Public Types

enum  flags : uint8_t { ASYNC = 1 }
 

Public Member Functions

 Client (const std::string &ip, int port)
 
 ~Client ()
 
 Client (const Client &other)=delete
 
Clientoperator= (const Client &other)=delete
 
 Client (Client &&other)=delete
 
Clientoperator= (Client &&other)=delete
 
void runOnce (const int &timeout_ms=-1)
 
void send (const sendInfo &info)
 
std::shared_ptr< IPacketpopPacket ()
 
size_t getQueueSize () const
 

Public Attributes

std::unordered_map< uint64_t, std::chrono::time_point< std::chrono::high_resolution_clock > > m_pings
 

Detailed Description

The Client side interface with the network module.

This class is responsible for managing the connection to the server and sending and receiving packets.

It is fully threadsafe and can be run in a separate thread.

About the sendInfo struct and the ASYNC flag:

if the client is running on another thread this flag can be usefull. when this flag is set the send function will only queue the packet to be sent. All of the serialization and the syscalls will be done in the client thread. If the packet being sent isnt highly delay sensitive this flag should be used. It wont change anything regarding performances if the client is running on the same thread as the sending thread.

About the ServerDisconnected exception:

It is the client's way of of notifying the user that the server disconnected.

the runOnce method will throw this exception if the server disconnected.

Member Enumeration Documentation

◆ flags

enum Client::flags : uint8_t
Enumerator
ASYNC 

Constructor & Destructor Documentation

◆ Client() [1/3]

Client::Client ( const std::string &  ip,
int  port 
)

◆ ~Client()

Client::~Client ( )

◆ Client() [2/3]

Client::Client ( const Client other)
delete

◆ Client() [3/3]

Client::Client ( Client &&  other)
delete

Member Function Documentation

◆ getQueueSize()

size_t Client::getQueueSize ( ) const

◆ operator=() [1/2]

Client & Client::operator= ( Client &&  other)
delete

◆ operator=() [2/2]

Client & Client::operator= ( const Client other)
delete

◆ popPacket()

std::shared_ptr< IPacket > Client::popPacket ( )

◆ runOnce()

void Client::runOnce ( const int &  timeout_ms = -1)

◆ send()

void Client::send ( const sendInfo info)

Member Data Documentation

◆ m_pings

std::unordered_map<uint64_t, std::chrono::time_point<std::chrono::high_resolution_clock> > Client::m_pings

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