A class that runs network thread and acts as a bridge between the server and clients. More...
#include <network_listener.hpp>
Classes | |
class | Observer |
Allows to receive notifications from network listener. More... | |
Public Types | |
typedef vector< MessagePackage > | MessageContainer |
Container type for network messages. | |
Public Member Functions | |
void | addObserver (Observer *observer) |
Add observer to listen for network events. | |
ConnectionAdapterSharedPtr | getAdapter () |
Return the adapter that this network listener uses. | |
ConnectionAdapter * | getConnectionAdapter (const int clientId) const |
Find the connection adapter that handles the connection for the given client. | |
virtual bool | getParameter (size_t id, size_t ¶m) |
Allows to query a listener-specific parameter. | |
string | getRemoteIPAddress (size_t handle) |
Gets the IP Address of the remote peer. | |
NetworkListener (ConnectDomainSharedPtr domain, MessagePackage::SerializationFormat serializationFormat) | |
Constructor. | |
int | purgeInactiveConnections () |
Clean up connections that are no longer active. | |
MessageArray | receive (size_t clientId, bool patchClientId=true) |
Retrieves incoming data packet from a given client. | |
void | removeObserver (Observer *observer) |
Remove observer. | |
void | reset () |
Resets the internal network listener state. | |
void | start (ConnectionAdapterSharedPtr connectionAdapter, const ConnectionAdapter::Parameters ¶meters) |
Starts listening connections, using given network adapter and parameters. | |
void | stop () |
Stop listening connections and tears down the networking thread. | |
bool | transmit (size_t clientId, const MessagePackage &message) |
Sends a data packet to given client. | |
void | useDiagnosticsManager (DiagnosticsManagerSharedPtr diagnosticsManager) |
Attach diagnostics manager to this network listener. | |
virtual | ~NetworkListener () |
Destructor. | |
Static Public Attributes | |
static const size_t | ParamTypeSerializationFormat = SERIALIZATION_FORMAT_PARAM_ID |
Use a parameter ID to query serialization format. | |
Protected Member Functions | |
void | run () |
Network thread function. | |
A class that runs network thread and acts as a bridge between the server and clients.
This class initializes connection adapter according to given parameters and starts a network thread. It is responsible of transmitting and receiving data through message translators and maintains connections of clients.
typedef vector<MessagePackage> kanzi::connect::NetworkListener::MessageContainer |
Container type for network messages.
kanzi::connect::NetworkListener::NetworkListener | ( | ConnectDomainSharedPtr | domain, |
MessagePackage::SerializationFormat | serializationFormat ) |
Constructor.
|
virtual |
Destructor.
void kanzi::connect::NetworkListener::addObserver | ( | Observer * | observer | ) |
Add observer to listen for network events.
observer | Observer to add. |
ConnectionAdapterSharedPtr kanzi::connect::NetworkListener::getAdapter | ( | ) |
Return the adapter that this network listener uses.
ConnectionAdapter * kanzi::connect::NetworkListener::getConnectionAdapter | ( | const int | clientId | ) | const |
Find the connection adapter that handles the connection for the given client.
clientId | Identifies the client. |
|
virtual |
Allows to query a listener-specific parameter.
Supported parameters: ParamTypeSerializationFormat
id | Id of the parameter. |
param | Value of the parameter (out). |
string kanzi::connect::NetworkListener::getRemoteIPAddress | ( | size_t | handle | ) |
Gets the IP Address of the remote peer.
handle | Identfies the remote peer. |
int kanzi::connect::NetworkListener::purgeInactiveConnections | ( | ) |
Clean up connections that are no longer active.
MessageArray kanzi::connect::NetworkListener::receive | ( | size_t | clientId, |
bool | patchClientId = true ) |
Retrieves incoming data packet from a given client.
clientId | The id of the client that sends the data. |
patchClientId | Patches the returned messages with the requested client identifier. |
void kanzi::connect::NetworkListener::removeObserver | ( | Observer * | observer | ) |
Remove observer.
observer | Observer to remove. |
void kanzi::connect::NetworkListener::reset | ( | ) |
Resets the internal network listener state.
|
protected |
Network thread function.
void kanzi::connect::NetworkListener::start | ( | ConnectionAdapterSharedPtr | connectionAdapter, |
const ConnectionAdapter::Parameters & | parameters ) |
Starts listening connections, using given network adapter and parameters.
connectionAdapter | Adapter to use for communication. |
parameters | Parameters for the network adapter. |
void kanzi::connect::NetworkListener::stop | ( | ) |
Stop listening connections and tears down the networking thread.
bool kanzi::connect::NetworkListener::transmit | ( | size_t | clientId, |
const MessagePackage & | message ) |
Sends a data packet to given client.
clientId | The id of the client that should receive the message. |
message | Message to be sent. |
void kanzi::connect::NetworkListener::useDiagnosticsManager | ( | DiagnosticsManagerSharedPtr | diagnosticsManager | ) |
Attach diagnostics manager to this network listener.
|
static |
Use a parameter ID to query serialization format.