Class to create a server that can detect clients processes and distribute messages to them using mapped/shared memory. More...
#include <messageserver.h>
Classes | |
class | Registry |
Registry to keep track of clients who want to receive data from the Message Server. Message Clients must register themselves to receive data from the Message Server. More... | |
Public Types | |
typedef MappedMemory::ID | ID |
ID Field. | |
typedef std::set< ID > | List |
Client/Registry list information. | |
Public Member Functions | |
MessageServer () | |
Constructor. | |
~MessageServer () | |
Destructor. | |
int | Initialize (const ID serverID, const unsigned int maxClients=DefaultMaxClients) |
Initializes the MessageServer. | |
int | Initialize (const std::string &serverID, const unsigned int maxClients=DefaultMaxClients) |
Initializes the MessageServer. | |
void | Shutdown () |
Stops the server and releases all connections to clients and registry. | |
bool | CreateConnection (const ID id) |
Optional method to force a connection attempt to a specific ID number. | |
bool | SendToClient (const ID id, const std::string &message) |
Sends a message to a specific subscribing client ID. | |
bool | SendToClient (const ID id, const Packet &message) |
Sends a message to a specific subscribing client ID. | |
bool | SendToAllClients (const std::string &message) |
Sends a message to all subscribing clients. | |
bool | SendToAllClients (const Packet &message) |
Sends a message to all subscribing clients. | |
bool | GetClientList (List &clients) const |
Get a list of all connected client IDs. | |
unsigned int | GetNumClients () const |
bool | IsInitialized () const |
Static Public Member Functions | |
static bool | IsServerPresent (const std::string &serverID) |
Method used to check if a server is running on the host machine. | |
Static Public Attributes | |
static const unsigned int | DefaultMaxClients = 25 |
Default value for max num of clients. |
Class to create a server that can detect clients processes and distribute messages to them using mapped/shared memory.
The Message Server acts as the single point of entry for message data that needs to be distributed. Message Clients (MessageClient class) can register to receive these message as they arrive.
Definition at line 62 of file messageserver.h.
ID Field.
Definition at line 66 of file messageserver.h.
typedef std::set<ID> CxUtils::MessageServer::List |
Client/Registry list information.
Definition at line 67 of file messageserver.h.
MessageServer::MessageServer | ( | ) |
Constructor.
Definition at line 496 of file messageserver.cpp.
MessageServer::~MessageServer | ( | ) |
Destructor.
Definition at line 506 of file messageserver.cpp.
bool MessageServer::CreateConnection | ( | const ID | id ) |
Optional method to force a connection attempt to a specific ID number.
The MessageServer class will automatically find and connect to MessageClients running on the host machine, however if it has not detected the connection yet, it is possible to force one using this interface.
[in] | id | The ID of the MessageClient to try create a connection to. |
Definition at line 627 of file messageserver.cpp.
bool MessageServer::GetClientList | ( | List & | clients ) | const |
Get a list of all connected client IDs.
[in] | clients | List of active client connections. |
Definition at line 768 of file messageserver.cpp.
unsigned int MessageServer::GetNumClients | ( | ) | const |
Definition at line 791 of file messageserver.cpp.
int MessageServer::Initialize | ( | const ID | serverID, |
const unsigned int | maxClients = DefaultMaxClients |
||
) |
Initializes the MessageServer.
[in] | serverID | Name of server to use (all clients must use this name to connect). For maximum portability between Windows and Linux, use an integer (in Windows you can use any string). |
[in] | maxClients | Maximum number of clients to allow connections to server (default is 25). |
Definition at line 525 of file messageserver.cpp.
int MessageServer::Initialize | ( | const std::string & | serverID, |
const unsigned int | maxClients = DefaultMaxClients |
||
) |
Initializes the MessageServer.
[in] | serverID | Name of server to use (all clients must use this name to connect). For maximum portability between Windows and Linux, use an integer (in Windows you can use any string). |
[in] | maxClients | Maximum number of clients to allow connections to server (default is 25). |
Definition at line 548 of file messageserver.cpp.
bool MessageServer::IsInitialized | ( | ) | const |
Definition at line 806 of file messageserver.cpp.
bool MessageServer::IsServerPresent | ( | const std::string & | serverID ) | [static] |
Method used to check if a server is running on the host machine.
[in] | serverID | The name/ID of the server to check for. |
Definition at line 825 of file messageserver.cpp.
bool MessageServer::SendToAllClients | ( | const Packet & | message ) |
Sends a message to all subscribing clients.
[in] | message | The message data to send. |
Definition at line 718 of file messageserver.cpp.
bool MessageServer::SendToAllClients | ( | const std::string & | message ) |
Sends a message to all subscribing clients.
[in] | message | The message data to send. |
Definition at line 743 of file messageserver.cpp.
bool MessageServer::SendToClient | ( | const ID | id, |
const std::string & | message | ||
) |
Sends a message to a specific subscribing client ID.
[in] | id | The ID of the client to send the message to. |
[in] | message | The message data to send. |
Definition at line 694 of file messageserver.cpp.
Sends a message to a specific subscribing client ID.
[in] | id | The ID of the client to send the message to. |
[in] | message | The message data to send. |
Definition at line 669 of file messageserver.cpp.
void MessageServer::Shutdown | ( | ) |
Stops the server and releases all connections to clients and registry.
Definition at line 590 of file messageserver.cpp.
const unsigned int CxUtils::MessageServer::DefaultMaxClients = 25 [static] |
Default value for max num of clients.
Definition at line 65 of file messageserver.h.