ionflux.org | Impressum

Ionflux::Tools::TCPServer Class Reference
[Network interface]

TCPServer. More...

#include <TCPServer.hpp>

Inheritance diagram for Ionflux::Tools::TCPServer:

Inheritance graph
[legend]
Collaboration diagram for Ionflux::Tools::TCPServer:

Collaboration graph
[legend]
List of all members.

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 ReportergetLog ()
 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.
IOMultiplexeriomp
 IO multiplexer.
bool manageIomp
 IO multiplexer memory management flag.
IOEvent serverSocketEvent
 IO event for the server socket.

Detailed Description

TCPServer.

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 & Destructor Documentation

Ionflux::Tools::TCPServer::TCPServer  ) 
 

Constructor.

Construct new TCPServer object.

Ionflux::Tools::TCPServer::TCPServer IOMultiplexer initIomp  ) 
 

Constructor.

Construct new TCPServer object.

Parameters:
initIomp IO multiplexer.

Ionflux::Tools::TCPServer::~TCPServer  )  [virtual]
 

Destructor.

Destruct TCPServer object.


Member Function Documentation

void Ionflux::Tools::TCPServer::addClient TCPRemotePeer client  )  [protected, virtual]
 

Add client.

Add a remote client to the client vector.

Parameters:
client Client to be added.

void Ionflux::Tools::TCPServer::broadcast const std::string &  bytes  )  [virtual]
 

Broadcast bytes.

Sends the specified byte string to all connected clients.

Parameters:
bytes The bytes to broadcast.

Reimplemented in Ionflux::Tools::TCPAuthServer, and Ionflux::Tools::TCPMessageServer.

void Ionflux::Tools::TCPServer::cleanup  )  [virtual]
 

Perform cleanup.

Shuts the server down and cleans up the resources used by the server.

void Ionflux::Tools::TCPServer::cleanupClients  )  [protected, virtual]
 

Clean up clients.

Removes disconnected clients from the peer vector.

void Ionflux::Tools::TCPServer::disconnect TCPRemotePeer peer  )  [protected, virtual]
 

Disconnect peer.

Causes the specified remote peer to be disconnected.

Parameters:
peer The remote peer to be disconnected.

Reporter & Ionflux::Tools::TCPServer::getLog  )  [virtual]
 

Get Console output/logging facility.

Returns:
The console output/logging facility used by this object.

unsigned int Ionflux::Tools::TCPServer::getMaxClients  )  [virtual]
 

Get maximum number of clients.

Returns:
Maximum number of clients.

int Ionflux::Tools::TCPServer::getPort  )  [virtual]
 

Get listening port.

Returns:
Listening port.

bool Ionflux::Tools::TCPServer::init  )  [virtual]
 

Initialize server.

Prepare the server for operation.

Returns:
true on success, false otherwise.

void Ionflux::Tools::TCPServer::onConnect TCPRemotePeer client  )  [protected, virtual]
 

Event handler for new connections.

This is called by the main loop whenever a new client connects.

Note:
Override this to implement your own connection handling.
Parameters:
client The client which caused the event.

Reimplemented in Ionflux::Tools::TCPAuthServer, and Ionflux::Tools::TCPMessageServer.

void Ionflux::Tools::TCPServer::onDisconnect TCPRemotePeer client  )  [protected, virtual]
 

Event handler for client disconnection.

This is called by the main loop whenever a client disconnects.

Note:
Override this to implement your own disconnection handling. However, do not expect to be able to write to the socket of the disconnected client! The client reference is provided for informational purposes only.
Parameters:
client The client which caused the event.

void Ionflux::Tools::TCPServer::onIO const IOEvent event  )  [virtual]
 

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.

Parameters:
event IO event..

Implements Ionflux::Tools::IOHandler.

void Ionflux::Tools::TCPServer::onReceive TCPRemotePeer client  )  [protected, virtual]
 

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.

Note:
Override this to implement your own received data handling. Remember that it is your responsibility to empty the receive buffer after you are done processing data.
Parameters:
client The client which caused the event.

Reimplemented in Ionflux::Tools::TCPMessageServer.

void Ionflux::Tools::TCPServer::onReject TCPRemotePeer client,
int  reason
[protected, virtual]
 

Event handler for rejected connections.

This is called by the main loop whenever a new client connection is rejected.

Note:
Override this to implement your own rejection handling. The socket is probably writable while the call lasts, but may be closed as soon as onReject returns.
Parameters:
client The client which caused the event.
reason The reason why the connection has been rejected.

void Ionflux::Tools::TCPServer::removeClient TCPRemotePeer client  )  [protected, virtual]
 

Remove client.

Remove a remote client from the client vector.

Parameters:
client Client to be removed.

void Ionflux::Tools::TCPServer::run  )  [virtual]
 

Run server.

Runs the server main loop. You must call init before starting the main loop.

See also:
init()

void Ionflux::Tools::TCPServer::setMaxClients unsigned int  newMaxClients  )  [virtual]
 

Set maximum number of clients.

Sets the maximum number of clients that may be connected to this server at the same time.

Note:
Set this to 0 to allow as many clients as possible. You can also set this to DEFAULT_MAX_CLIENTS to use the default value.
Parameters:
newMaxClients Maximum number of clients.

void Ionflux::Tools::TCPServer::setPort int  newPort  )  [virtual]
 

Set port.

Sets the port on which this server will listen for incoming connections.

Parameters:
newPort Port number.

void Ionflux::Tools::TCPServer::shutdownHandler int  signum  )  [static]
 

Shutdown handler.

Signal handler for signals that will cause the server to shutdown.

Parameters:
signum Signal.


Member Data Documentation

std::vector<TCPRemotePeer *> Ionflux::Tools::TCPServer::clients [protected]
 

Vector of connected clients.

int Ionflux::Tools::TCPServer::currentClientID [protected]
 

Current client ID.

const int Ionflux::Tools::TCPServer::DEFAULT_MAX_CLIENTS = 0 [static]
 

Default maximum number of clients.

IOMultiplexer* Ionflux::Tools::TCPServer::iomp [protected]
 

IO multiplexer.

Ionflux::Tools::Reporter Ionflux::Tools::TCPServer::log [protected]
 

Console output/logging.

bool Ionflux::Tools::TCPServer::manageIomp [protected]
 

IO multiplexer memory management flag.

unsigned int Ionflux::Tools::TCPServer::maxClients [protected]
 

Maximum number of clients.

const int Ionflux::Tools::TCPServer::REJECTED_REASON_MAX_CLIENTS = 0 [static]
 

Connection rejected: Maximum number of clients connected.

TCPSocket Ionflux::Tools::TCPServer::serverSocket [protected]
 

Server socket.

IOEvent Ionflux::Tools::TCPServer::serverSocketEvent [protected]
 

IO event for the server socket.

std::vector<TCPRemotePeer *> Ionflux::Tools::TCPServer::trash [protected]
 

Vector of disconnected clients.


The documentation for this class was generated from the following files:
Generated on Tue Mar 14 21:11:06 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6