ionflux.org | Impressum

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

Generic TCP Client. More...

#include <TCPClient.hpp>

Inheritance diagram for Ionflux::Tools::TCPClient:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TCPClient ()
 Constructor.
 TCPClient (bool initInteractive)
 Constructor.
 TCPClient (bool initInteractive, IOMultiplexer *initIomp)
 Constructor.
virtual ~TCPClient ()
 Destructor.
virtual void onInput (const std::string &line)
 Event handler for standard input.
virtual void run ()
 Run client.
virtual void cleanup ()
 Perform cleanup.
virtual bool addConnection (const std::string &host, int port)
 Add connection.
virtual void broadcast (const std::string &bytes)
 Broadcast bytes.
virtual void onIO (const IOEvent &event)
 Handle IO event.
virtual ReportergetLog ()
 Get Console output/logging facility.

Static Public Member Functions

static void shutdownHandler (int signum)
 Shutdown handler.

Protected Member Functions

virtual void addPeer (TCPRemotePeer *peer)
 Add peer.
virtual void removePeer (TCPRemotePeer *peer)
 Remove peer.
virtual void cleanupPeers ()
 Clean up peers.
virtual void onConnect (TCPRemotePeer &peer)
 Event handler for new connections.
virtual void onReceive (TCPRemotePeer &peer)
 Event handler for received data.
virtual void onDisconnect (TCPRemotePeer &peer)
 Event handler for peer disconnection.
virtual void disconnect (TCPRemotePeer *peer)
 Disconnect peer.

Protected Attributes

Ionflux::Tools::Reporter log
 Console output/logging.
bool interactive
 Interactive flag.
std::vector< TCPRemotePeer * > peers
 Vector of connected peers.
std::vector< TCPRemotePeer * > trash
 Vector of disconnected peers.
int currentPeerID
 Current peer ID.
IOMultiplexeriomp
 IO multiplexer.
bool manageIomp
 IO multiplexer memory management flag.
IOEvent stdinEvent
 IO event for standard input.

Detailed Description

Generic TCP Client.

A generic TCP client, supporting an arbitrary number of peers. You can implement your own protocol by overriding the onConnect(), onReceive() and onDisconnect() event handlers. The TCP client can either be interactive (meaning it reads data from standard input) or non-interactive (meaning it doesn't read anything from standard input).


Constructor & Destructor Documentation

Ionflux::Tools::TCPClient::TCPClient  ) 
 

Constructor.

Construct new TCPClient object.

Ionflux::Tools::TCPClient::TCPClient bool  initInteractive  ) 
 

Constructor.

Construct new TCPClient object.

Parameters:
initInteractive Whether this client should run interactively (i.e. read data from standard input).

Ionflux::Tools::TCPClient::TCPClient bool  initInteractive,
IOMultiplexer initIomp
 

Constructor.

Construct new TCPClient object.

Parameters:
initInteractive Whether this client should run interactively (i.e. read data from standard input).
initIomp IO multiplexer.

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

Destructor.

Destruct TCPClient object.


Member Function Documentation

bool Ionflux::Tools::TCPClient::addConnection const std::string &  host,
int  port
[virtual]
 

Add connection.

Attempts to establish a connection to the specified host and port. On success, the new connection will be maintained by the TCP client.

Parameters:
host Hostname or IP address of the remote host.
port Port to connect to.
Returns:
true on success, false otherwise.

void Ionflux::Tools::TCPClient::addPeer TCPRemotePeer peer  )  [protected, virtual]
 

Add peer.

Add a remote peer to the peer vector.

Parameters:
peer Peer to be added.

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

Broadcast bytes.

Sends the specified byte string to all connected peers.

Parameters:
bytes The bytes to broadcast.

Reimplemented in Ionflux::Tools::TCPAuthClient, and Ionflux::Tools::TCPMessageClient.

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

Perform cleanup.

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

void Ionflux::Tools::TCPClient::cleanupPeers  )  [protected, virtual]
 

Clean up peers.

Removes disconnected peers from the peer vector.

void Ionflux::Tools::TCPClient::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::TCPClient::getLog  )  [virtual]
 

Get Console output/logging facility.

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

void Ionflux::Tools::TCPClient::onConnect TCPRemotePeer peer  )  [protected, virtual]
 

Event handler for new connections.

This is called by the main loop whenever a connection to a peer is successfully established.

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

Reimplemented in Ionflux::Tools::TCPAuthClient, and Ionflux::Tools::TCPMessageClient.

void Ionflux::Tools::TCPClient::onDisconnect TCPRemotePeer peer  )  [protected, virtual]
 

Event handler for peer disconnection.

This is called by the main loop whenever a peer 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 peer! The peer reference is provided for informational purposes only.
Parameters:
peer The peer which caused the event.

void Ionflux::Tools::TCPClient::onInput const std::string &  line  )  [virtual]
 

Event handler for standard input.

For interactive clients, this is called by the main loop whenever data is available on standard input.

Parameters:
line Data from standard input.

Reimplemented in Ionflux::Tools::TCPMessageClient.

void Ionflux::Tools::TCPClient::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::TCPClient::onReceive TCPRemotePeer peer  )  [protected, virtual]
 

Event handler for received data.

This is called by the main loop whenever data is received from a peer. The received bytes will be appended to the receive buffer of the remote peer.

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:
peer The peer which caused the event.

Reimplemented in Ionflux::Tools::TCPMessageClient.

void Ionflux::Tools::TCPClient::removePeer TCPRemotePeer peer  )  [protected, virtual]
 

Remove peer.

Remove a remote peer from the peer vector.

Parameters:
peer Peer to be removed.

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

Run client.

Runs the client main loop.

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

Shutdown handler.

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

Parameters:
signum Signal.


Member Data Documentation

int Ionflux::Tools::TCPClient::currentPeerID [protected]
 

Current peer ID.

bool Ionflux::Tools::TCPClient::interactive [protected]
 

Interactive flag.

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

IO multiplexer.

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

Console output/logging.

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

IO multiplexer memory management flag.

std::vector<TCPRemotePeer *> Ionflux::Tools::TCPClient::peers [protected]
 

Vector of connected peers.

IOEvent Ionflux::Tools::TCPClient::stdinEvent [protected]
 

IO event for standard input.

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

Vector of disconnected peers.


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