#include <TCPServer.hpp>
Inheritance diagram for Ionflux::Tools::TCPServer:
Public Member Functions | |
TCPServer () | |
Constructor. | |
TCPServer (IOMultiplexer *initIomp) | |
Constructor. | |
virtual | ~TCPServer () |
Destructor. | |
virtual bool | init () |
Initialize server. | |
virtual void | run () |
Run server. | |
virtual void | cleanup () |
Perform cleanup. | |
virtual void | broadcast (const std::string &bytes) |
Broadcast bytes. | |
virtual void | onIO (const IOEvent &event) |
Handle IO event. | |
virtual void | setMaxClients (unsigned int newMaxClients) |
Set maximum number of clients. | |
virtual void | setPort (int newPort) |
Set port. | |
virtual unsigned int | getMaxClients () |
Get maximum number of clients. | |
virtual int | getPort () |
Get listening port. | |
virtual Reporter & | getLog () |
Get Console output/logging facility. | |
Static Public Member Functions | |
static void | shutdownHandler (int signum) |
Shutdown handler. | |
Static Public Attributes | |
static const int | DEFAULT_MAX_CLIENTS = 0 |
Default maximum number of clients. | |
static const int | REJECTED_REASON_MAX_CLIENTS = 0 |
Connection rejected: Maximum number of clients connected. | |
Protected Member Functions | |
virtual void | addClient (TCPRemotePeer *client) |
Add client. | |
virtual void | removeClient (TCPRemotePeer *client) |
Remove client. | |
virtual void | cleanupClients () |
Clean up clients. | |
virtual void | onConnect (TCPRemotePeer &client) |
Event handler for new connections. | |
virtual void | onReject (TCPRemotePeer &client, int reason) |
Event handler for rejected connections. | |
virtual void | onReceive (TCPRemotePeer &client) |
Event handler for received data. | |
virtual void | onDisconnect (TCPRemotePeer &client) |
Event handler for client disconnection. | |
virtual void | disconnect (TCPRemotePeer *peer) |
Disconnect peer. | |
Protected Attributes | |
Ionflux::Tools::Reporter | log |
Console output/logging. | |
TCPSocket | serverSocket |
Server socket. | |
std::vector< TCPRemotePeer * > | clients |
Vector of connected clients. | |
std::vector< TCPRemotePeer * > | trash |
Vector of disconnected clients. | |
unsigned int | maxClients |
Maximum number of clients. | |
int | currentClientID |
Current client ID. | |
IOMultiplexer * | iomp |
IO multiplexer. | |
bool | manageIomp |
IO multiplexer memory management flag. | |
IOEvent | serverSocketEvent |
IO event for the server socket. |
A generic TCP server. You can implement your own protocol by deriving a class from TCPServer and overriding the onConnect(), onReject(), onReceive() and onDisconnect() event handlers.
|
Constructor. Construct new TCPServer object. |
|
Constructor. Construct new TCPServer object.
|
|
Destructor. Destruct TCPServer object. |
|
Add client. Add a remote client to the client vector.
|
|
Broadcast bytes. Sends the specified byte string to all connected clients.
Reimplemented in Ionflux::Tools::TCPAuthServer, and Ionflux::Tools::TCPMessageServer. |
|
Perform cleanup. Shuts the server down and cleans up the resources used by the server. |
|
Clean up clients. Removes disconnected clients from the peer vector. |
|
Disconnect peer. Causes the specified remote peer to be disconnected.
|
|
Get Console output/logging facility.
|
|
Get maximum number of clients.
|
|
Get listening port.
|
|
Initialize server. Prepare the server for operation.
|
|
Event handler for new connections. This is called by the main loop whenever a new client connects.
Reimplemented in Ionflux::Tools::TCPAuthServer, and Ionflux::Tools::TCPMessageServer. |
|
Event handler for client disconnection. This is called by the main loop whenever a client disconnects.
|
|
Handle IO event. Pass an IO event to the object for processing. The IOEvent will have its type flags set according to the events that have been triggered.
Implements Ionflux::Tools::IOHandler. |
|
Event handler for received data. This is called by the main loop whenever data is received from a client. The received bytes will be appended to the receive buffer of the remote client.
Reimplemented in Ionflux::Tools::TCPMessageServer. |
|
Event handler for rejected connections. This is called by the main loop whenever a new client connection is rejected.
|
|
Remove client. Remove a remote client from the client vector.
|
|
Run server. Runs the server main loop. You must call init before starting the main loop.
|
|
Set maximum number of clients. Sets the maximum number of clients that may be connected to this server at the same time.
|
|
Set port. Sets the port on which this server will listen for incoming connections.
|
|
Shutdown handler. Signal handler for signals that will cause the server to shutdown.
|
|
Vector of connected clients.
|
|
Current client ID.
|
|
Default maximum number of clients.
|
|
IO multiplexer.
|
|
Console output/logging.
|
|
IO multiplexer memory management flag.
|
|
Maximum number of clients.
|
|
Connection rejected: Maximum number of clients connected.
|
|
Server socket.
|
|
IO event for the server socket.
|
|
Vector of disconnected clients.
|