4 #include <unordered_map>
15 using std::unordered_map;
60 inline const string&
getIp()
const {
76 inline const string&
getKey()
const {
99 void send(
UDPPacket* packet,
bool safe =
true,
bool deleteFrame =
true);
134 virtual void onRequest(
const UDPPacket* packet,
const uint32_t messageId,
const uint8_t retries) = 0;
Base class for network server clients.
Base class for network UDP server clients.
void cleanUpSafeMessages()
Clean up safe messages.
void init()
initiates this network client
void send(UDPPacket *packet, bool safe=true, bool deleteFrame=true)
Sends a frame to client, takes over ownership of frame.
unordered_map< uint32_t, Message * > MessageMapSafe
const string & getKey() const
Client identification key.
MessageMapSafe messageMapSafe
const uint16_t getPort() const
returns client port
void fireEvent(const string &type)
fires an custom event
void close()
Shuts down this network client.
static const uint64_t MESSAGESSAFE_KEEPTIME
uint64_t getRetryTime(const uint8_t retries)
UDPServer * getServer()
Returns server.
const string & getIp() const
returns client's ip
void shutdown()
Shuts down this network client.
virtual void onPacketReceived(const UDPPacket *packet, const uint32_t messageId=0, const uint8_t retries=0)
Event, which will be called if packet has been received, defaults to worker thread pool.
UDPServerIOThread * ioThread
virtual void onRequest(const UDPPacket *packet, const uint32_t messageId, const uint8_t retries)=0
To be overwritten with a request handler, will be called from worker.
const bool setKey(const string &key)
sets the clients identification key
const uint32_t getClientId()
Get client id.
UDPServerClient(const uint32_t clientId, const std::string &ip, const uint16_t port)
public constructor should be called in any subclass of UDPNetworkServer
static UDPPacket * createPacket()
Creates a packet to be used with send.
virtual ~UDPServerClient()
public destructor, should only be called implicitly by Reference::releaseReference()
Mutex messageMapSafeMutex
void sendConnected()
Sends an connect message to client.
volatile bool shutdownRequested
bool processSafeMessage(const uint32_t messageId)
Checks if message has already been processed and sends an acknowlegdement to client / safe client mes...
UDP Network server IO thread.
Base class for network UDP servers.
std::exception Exception
Exception base class.
#define FORBID_CLASS_COPY(CLASS)