TDME2 1.9.121
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
UDPServerClient Class Referenceabstract

Base class for network UDP server clients. More...

#include <tdme/network/udpserver/UDPServerClient.h>

Inheritance diagram for UDPServerClient:
Inheritance graph
Collaboration diagram for UDPServerClient:
Collaboration graph

Classes

struct  Message
 

Public Member Functions

 UDPServerClient (const uint32_t clientId, const std::string &ip, const unsigned int port)
 public constructor should be called in any subclass of UDPNetworkServer More...
 
UDPServergetServer ()
 Returns server. More...
 
const uint32_t getClientId ()
 Get client id. More...
 
const string & getIp () const
 returns client's ip More...
 
const unsigned int getPort () const
 returns client port More...
 
const string & getKey () const
 Client identification key. More...
 
const bool setKey (const string &key)
 sets the clients identification key More...
 
void send (stringstream *frame, bool safe=true, bool deleteFrame=true)
 Sends a frame to client, takes over ownership of frame. More...
 
bool processSafeMessage (const uint32_t messageId)
 Checks if message has already been processed and sends an acknowlegdement to client / safe client messages. More...
 
uint64_t getRetryTime (const uint8_t retries)
 
void fireEvent (const string &type)
 fires an custom event More...
 
void shutdown ()
 Shuts down this network client. More...
 
- Public Member Functions inherited from ServerClient
virtual const string & getIp () const =0
 returns client's ip More...
 
virtual const unsigned int getPort () const =0
 returns client port More...
 
virtual const string & getKey () const =0
 Client identification key. More...
 
virtual const bool setKey (const string &key)=0
 sets the clients identification key More...
 
stringstream * createFrame ()
 Creates a frame to be used with send. More...
 
virtual void shutdown ()=0
 Shuts down this network client. More...
 
- Public Member Functions inherited from Reference
 Reference ()
 Public constructor. More...
 
virtual ~Reference ()
 destructor More...
 
void acquireReference ()
 acquires a reference, incrementing the counter More...
 
void releaseReference ()
 releases a reference, thus decrementing the counter and delete it if reference counter is zero More...
 
virtual void onDelete ()
 Callback method to be overridden, will be called if object will be deleted. More...
 

Static Public Member Functions

static stringstream * createFrame ()
 Creates a frame to be used with send. More...
 

Protected Member Functions

virtual ~UDPServerClient ()
 public destructor, should only be called implicitly by Reference::releaseReference() More...
 
virtual void onRequest (stringstream *frame, const uint32_t messageId, const uint8_t retries)=0
 To be overwritten with a request handler, will be called from worker. More...
 
virtual void onClose ()=0
 
virtual void onFrameReceived (stringstream *frame, const uint32_t messageId=0, const uint8_t retries=0)
 Event, which will be called if frame has been received, defaults to worker thread pool. More...
 
void close ()
 Shuts down this network client. More...
 
void init ()
 initiates this network client More...
 
- Protected Member Functions inherited from ServerClient
virtual void onRequest (stringstream *frame, const uint32_t messageId, const uint8_t retries)=0
 To be overwritten with a request handler, will be called from worker. More...
 
virtual void onInit ()=0
 
virtual void onClose ()=0
 
virtual void onCustom (const string &type)=0
 
virtual void onFrameReceived (stringstream *frame, const uint32_t messageId=0, const uint8_t retries=0)=0
 Event, which will be called if frame has been received, defaults to worker thread pool. More...
 
virtual void close ()=0
 Shuts down this network client. More...
 

Protected Attributes

UDPServerserver
 
UDPServerIOThreadioThread
 
uint32_t clientId
 
std::string ip
 
unsigned int port
 
- Protected Attributes inherited from ServerClient
std::string key
 

Private Types

typedef map< uint32_t, MessageMessageMapSafe
 

Private Member Functions

void sendConnected ()
 Sends an connect message to client. More...
 
void cleanUpSafeMessages ()
 Clean up safe messages. More...
 

Private Attributes

volatile bool shutdownRequested
 
Mutex messageMapSafeMutex
 
MessageMapSafe messageMapSafe
 

Static Private Attributes

static const uint64_t MESSAGESSAFE_KEEPTIME = 5000L
 

Friends

class UDPServer
 
class UDPServerIOThread
 

Additional Inherited Members

- Static Public Attributes inherited from ServerClient
static STATIC_DLL_IMPEXT const char * KEY_PREFIX_UNNAMED = "unnamed."
 

Detailed Description

Base class for network UDP server clients.

Author
Andreas Drewke

Definition at line 30 of file UDPServerClient.h.

Member Typedef Documentation

◆ MessageMapSafe

typedef map<uint32_t, Message> MessageMapSafe
private

Definition at line 166 of file UDPServerClient.h.

Constructor & Destructor Documentation

◆ UDPServerClient()

UDPServerClient ( const uint32_t  clientId,
const std::string &  ip,
const unsigned int  port 
)

public constructor should be called in any subclass of UDPNetworkServer

Parameters
clientIdclient id
ipip
portport

Definition at line 27 of file UDPServerClient.cpp.

◆ ~UDPServerClient()

~UDPServerClient ( )
protectedvirtual

public destructor, should only be called implicitly by Reference::releaseReference()

Definition at line 42 of file UDPServerClient.cpp.

Member Function Documentation

◆ cleanUpSafeMessages()

void cleanUpSafeMessages ( )
private

Clean up safe messages.

Definition at line 265 of file UDPServerClient.cpp.

◆ close()

void close ( )
protectedvirtual

Shuts down this network client.

Implements ServerClient.

Definition at line 213 of file UDPServerClient.cpp.

◆ createFrame()

stringstream * createFrame ( )
static

Creates a frame to be used with send.

Returns
frame to be send

Definition at line 76 of file UDPServerClient.cpp.

◆ fireEvent()

void fireEvent ( const string &  type)

fires an custom event

Definition at line 246 of file UDPServerClient.cpp.

◆ getClientId()

const uint32_t getClientId ( )

Get client id.

Returns
client id

Definition at line 49 of file UDPServerClient.cpp.

◆ getIp()

const string & getIp ( ) const
virtual

returns client's ip

Returns
client ip

Implements ServerClient.

Definition at line 53 of file UDPServerClient.cpp.

◆ getKey()

const string & getKey ( ) const
virtual

Client identification key.

Returns
client key

Implements ServerClient.

Definition at line 61 of file UDPServerClient.cpp.

◆ getPort()

const unsigned int getPort ( ) const
virtual

returns client port

Returns
client port

Implements ServerClient.

Definition at line 57 of file UDPServerClient.cpp.

◆ getRetryTime()

uint64_t getRetryTime ( const uint8_t  retries)
Returns
time passed until a retry was acknowledged

Definition at line 285 of file UDPServerClient.cpp.

◆ getServer()

UDPServer * getServer ( )

Returns server.

Returns
server

Definition at line 45 of file UDPServerClient.cpp.

◆ init()

void init ( )
protected

initiates this network client

Definition at line 229 of file UDPServerClient.cpp.

◆ onClose()

virtual void onClose ( )
protectedpure virtual

Implements ServerClient.

◆ onFrameReceived()

void onFrameReceived ( stringstream *  frame,
const uint32_t  messageId = 0,
const uint8_t  retries = 0 
)
protectedvirtual

Event, which will be called if frame has been received, defaults to worker thread pool.

Parameters
frameframe
messageIdmessage id (upd server only)
retriesretries (udp server only)

Implements ServerClient.

Definition at line 188 of file UDPServerClient.cpp.

◆ onRequest()

virtual void onRequest ( stringstream *  frame,
const uint32_t  messageId,
const uint8_t  retries 
)
protectedpure virtual

To be overwritten with a request handler, will be called from worker.

Parameters
frameframe
messageIdmessage id
retriesretries

Implements ServerClient.

◆ processSafeMessage()

bool processSafeMessage ( const uint32_t  messageId)

Checks if message has already been processed and sends an acknowlegdement to client / safe client messages.

Parameters
messageIdmessage id

Definition at line 111 of file UDPServerClient.cpp.

◆ send()

void send ( stringstream *  frame,
bool  safe = true,
bool  deleteFrame = true 
)

Sends a frame to client, takes over ownership of frame.

Parameters
frameframe data
safesafe, requires ack and retransmission
deleteFramedelete frame

Definition at line 83 of file UDPServerClient.cpp.

◆ sendConnected()

void sendConnected ( )
private

Sends an connect message to client.

Definition at line 161 of file UDPServerClient.cpp.

◆ setKey()

const bool setKey ( const string &  key)
virtual

sets the clients identification key

Parameters
&keyclient identification key
Returns
if setting the key was succesful

Implements ServerClient.

Definition at line 65 of file UDPServerClient.cpp.

◆ shutdown()

void shutdown ( )
virtual

Shuts down this network client.

Implements ServerClient.

Definition at line 184 of file UDPServerClient.cpp.

Friends And Related Function Documentation

◆ UDPServer

friend class UDPServer
friend

Definition at line 31 of file UDPServerClient.h.

◆ UDPServerIOThread

friend class UDPServerIOThread
friend

Definition at line 32 of file UDPServerClient.h.

Member Data Documentation

◆ clientId

uint32_t clientId
protected

Definition at line 155 of file UDPServerClient.h.

◆ ioThread

UDPServerIOThread* ioThread
protected

Definition at line 154 of file UDPServerClient.h.

◆ ip

std::string ip
protected

Definition at line 156 of file UDPServerClient.h.

◆ messageMapSafe

MessageMapSafe messageMapSafe
private

Definition at line 181 of file UDPServerClient.h.

◆ messageMapSafeMutex

Mutex messageMapSafeMutex
private

Definition at line 180 of file UDPServerClient.h.

◆ MESSAGESSAFE_KEEPTIME

const uint64_t MESSAGESSAFE_KEEPTIME = 5000L
staticprivate

Definition at line 160 of file UDPServerClient.h.

◆ port

unsigned int port
protected

Definition at line 157 of file UDPServerClient.h.

◆ server

UDPServer* server
protected

Definition at line 153 of file UDPServerClient.h.

◆ shutdownRequested

volatile bool shutdownRequested
private

Definition at line 179 of file UDPServerClient.h.


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