#include <TCPClient.hpp>
Inheritance diagram for Ionflux::Tools::TCPClient:
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 Reporter & | getLog () |
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. | |
IOMultiplexer * | iomp |
IO multiplexer. | |
bool | manageIomp |
IO multiplexer memory management flag. | |
IOEvent | stdinEvent |
IO event for standard input. |
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. Construct new TCPClient object. |
|
Constructor. Construct new TCPClient object.
|
|
Constructor. Construct new TCPClient object.
|
|
Destructor. Destruct TCPClient object. |
|
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.
|
|
Add peer. Add a remote peer to the peer vector.
|
|
Broadcast bytes. Sends the specified byte string to all connected peers.
Reimplemented in Ionflux::Tools::TCPAuthClient, and Ionflux::Tools::TCPMessageClient. |
|
Perform cleanup. Shuts the client down and cleans up the resources used by the client. |
|
Clean up peers. Removes disconnected peers from the peer vector. |
|
Disconnect peer. Causes the specified remote peer to be disconnected.
|
|
Get Console output/logging facility.
|
|
Event handler for new connections. This is called by the main loop whenever a connection to a peer is successfully established.
Reimplemented in Ionflux::Tools::TCPAuthClient, and Ionflux::Tools::TCPMessageClient. |
|
Event handler for peer disconnection. This is called by the main loop whenever a peer disconnects.
|
|
Event handler for standard input. For interactive clients, this is called by the main loop whenever data is available on standard input.
Reimplemented in Ionflux::Tools::TCPMessageClient. |
|
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 peer. The received bytes will be appended to the receive buffer of the remote peer.
Reimplemented in Ionflux::Tools::TCPMessageClient. |
|
Remove peer. Remove a remote peer from the peer vector.
|
|
Run client. Runs the client main loop. |
|
Shutdown handler. Signal handler for signals that will cause the client to shutdown.
|
|
Current peer ID.
|
|
Interactive flag.
|
|
IO multiplexer.
|
|
Console output/logging.
|
|
IO multiplexer memory management flag.
|
|
Vector of connected peers.
|
|
IO event for standard input.
|
|
Vector of disconnected peers.
|