class CAVERNplus_tcpReflector_c

TCP Reflector class

Public Methods

int checkForNewClients ()
Call this as often as you wish to check for new clients
int init (int incomingPort=7000, int maxClients = 64)
Initialize the reflector
void intercept (int (*callback) (CAVERNplus_tcpReflectorClient_c *client, char** buffer, int *bufferSize, void *userData), void* userData)
Intercept incoming messages and call a user-defined callback function
void interceptNewConnection (void (*callback) (CAVERNplus_tcpReflectorClient_c *newClient, void* userData), void *userData)
Intercept any new connections that are formed
int process ()
Call this within a while loop to let the reflector continuously do its processing
void sendToAll (char* buffer, int dataSize)
Send data to all clients connected to the reflector

Public


const int CAVERNplus_tcpReflector_c::OK
Status ok.
const int CAVERNplus_tcpReflector_c::FAILED
Status failed.
const int CAVERNplus_tcpReflector_c::MEM_ALLOC_ERR
Memory allocation error.
const int CAVERNplus_tcpReflector_c::NEW_CONNECTION_ESTABLISHED
New client has been connected.
const int CAVERNplus_tcpReflector_c::TOO_MANY_CLIENTS
Reflector cannot handle any more connections
const int CAVERNplus_tcpReflector_c::NO_NEW_CONNECTION
No new connection.
const int CAVERNplus_tcpReflector_c::NON_BLOCKING_HAS_NO_DATA
A non-blocking read had no data available to read.
const int CAVERNplus_tcpReflector_c::SKIP_DISTRIBUTION
Skip the data distribution process. Used in user callback. See intercept().

Documentation

TCP Reflector class. This class treats TCP streams as discrete packets/messages that can be reflected to multiple connected clients. Clients must be created using CAVERNplus_tcpReflectorClient_c in order to interpret the TCP stream correctly. Hence do NOT attempt to use CAVERNplus_tcpClient_c to connect to a TCP reflector or it will corrupt the TCP reflector stream. This reflector has 2 main functions: checkForNewClients() and process(). checkForNewClients, as the name suggests, checks to see if any new clients wish to connect to the reflector. Process() does the actual work of data reflection.

checkForNewClients is called everytime process() is called. If you want the check to be done more frequently you need to do it yourself. Similarly if you want the process() call done more frequently it is up to you to do it. I recommend threading those two off and setting up a mutex so that you do not do process() and checkForNewClients() at the same time.

int init(int incomingPort=7000, int maxClients = 64)
Initialize the reflector
Returns:
Either CAVERNplus_tcpReflector_c::OK,FAILED,MEM_ALLOC_ERR.
Parameters:
incomingPort - is listening port for incoming connections.
maxClients - is the max number of clients the reflector will manage.

int process()
Call this within a while loop to let the reflector continuously do its processing
Returns:
Either CAVERNplus_tcpReflector_c::OK,MEM_ALLOC_ERR

int checkForNewClients()
Call this as often as you wish to check for new clients. Note. If you do this in a separate thread then you must set up a mutex so that you do not call the proces() call and this call at the same time. The process() call itself has imbedded in it 1 check for each time you call it.
Returns:
Either CAVERNplus_tcpReflector_c::NEW_CONNECTION_ESTABLISHED, NO_NEW_CONNECTION, TOO_MANY_CLIENTS.

void intercept(int (*callback) (CAVERNplus_tcpReflectorClient_c *client, char** buffer, int *bufferSize, void *userData), void* userData)
Intercept incoming messages and call a user-defined callback function. If you want you can also alter the buffer completely so that the reflector will reflect an entirely differet message. You can do this by changing the contents of the buffer or by replacing the buffer entirely by allocating memory for your new buffer and stuffing it with your own data. Note however that you must remember to deallocate memory for the original buffer before substituting it with yours. If after your callback function exits you do not wish the reflector to deliver the contents of the buffer, return with CAVERN_tcpReflector_c::SKIP_DISTRIBUTION. Otherwise just return CAVERN_tcpReflector_c::OK; Callback function will also be given a pointer to the CAVERNplus_tcpReflectorClient_c object that can then be used to send data directly to the originating client if necessary.

void interceptNewConnection(void (*callback) (CAVERNplus_tcpReflectorClient_c *newClient, void* userData), void *userData)
Intercept any new connections that are formed. This allows you to send private data to the newly formed connection before it assumes its data reflection duties. Callback function will be given a pointer to the CAVERNplus_tcpReflectorClient_c object that can then be used to send data directly to the client.


This class has no child classes.

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de