Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Examples  

SUETcpClientSession Class Reference

Client TCP session. More...

#include <sue_tcpc.hpp>

Inheritance diagram for SUETcpClientSession:

Inheritance graph
[legend]
Collaboration diagram for SUETcpClientSession:

Collaboration graph
[legend]
List of all members.

Public Methods

const char * InspectAddr () const
int InspectPort () const
const char * InspectLocalAddr () const
int InspectLocalPort () const
 SUETcpClientSession (const char *ipaddr, int ipport, int timeout, const char *greeting=0, const char *local_ip=0, int localport=0)
 Constructor.

virtual ~SUETcpClientSession ()
 Destructor.

bool Up (SUEEventSelector *a_selector)
 Actually start the session.

bool Up (SUEEventSelector *a_selector, const char *src_ipaddr, int src_port)
 Start the session performing connect from the given address.

void Down ()
 Shuts the session down.

virtual void HandleConnectionFailure ()
 What to do if connection attempt failed.

virtual void HandleNewInput ()=0
 Hook for handling new input.


Detailed Description

Client TCP session.

This class deals with a client TCP session. You create your own class to represent whatever protocol you need. It is done in methods HandleNewInput() and HandleSessionTerminatingEvent() (see the UPPGenericDuplexSession class description for details on implementing a session object).

Having the class, you first create an object as appropriate, and then start your session by calling Up() method. Your handling methods may instruct other objects to write something to the session whenever they need (that is done using WriteChars() method). The session may be shut down any time using Down() method (the preferred way). If you need to notify someone the session's dead, override the ShutdownHook() method. In case you do, be sure to call Down() or Shutdown() from your destructor, or else the session will shut down during destruction of the base class so wrong version of ShutdownHook() is called. Yes, it IS safe to call Down() for already-shuted session. ShutdownHook() is called only once, when the session is actually shot.

Examples:

hellobot.cpp.


Constructor & Destructor Documentation

SUETcpClientSession::SUETcpClientSession const char *    ipaddr,
int    ipport,
int    timeout,
const char *    greeting = 0,
const char *    local_ip = 0,
int    localport = 0
 

Constructor.

Parameters:
ipaddr  - the ip-address to connect to (in the text representation)
ipport  - the TCP port to connect to.
timeout  - the timeout in seconds. If a session idles more than than many seconds, it dies.
greeting  - the string to send via the socket right after connection is estableshed, without waiting for any data from the other end. If unneeded, NULL may be passed.
local_ip  - the local ip to use (or NULL to let the system choose)
localport  - the local TCP port (or 0 to let the system choose)
Note:
constructor just constructs the object. It doesn't create a socket nor does it try to connect. See the Up() method.
Up() will call bind() in case the local_ip or local_port or both are specified. Otherwise, bind() isn't used.

virtual SUETcpClientSession::~SUETcpClientSession   [virtual]
 

Destructor.


Member Function Documentation

void SUETcpClientSession::Down   [inline]
 

Shuts the session down.

The preferred method to shut the session down.

virtual void SUETcpClientSession::HandleConnectionFailure   [inline, virtual]
 

What to do if connection attempt failed.

This function is called when, after connect(2) had been called, select(2) indicated writability while getsockopt(2) indicated the connection wasn't successfull. By other words, the session is considered 'up' (because Up() returned true), but after that, it couldn't connect to the destination.

By default, the function calls Shutdown() just like all the similar methods like HandleSessionTimeout() etc, but you can override it to customize this.

virtual void SUETcpClientSession::HandleNewInput   [pure virtual]
 

Hook for handling new input.

This function is called whenever new data is read from the session channel (that is, select(2) told us there is possibility to read, and read(2) got more than zero chars from the session's file descriptor).

All the chars are appended to the inputbuffer before this function is called.

Implements SUEGenericDuplexSession.

Examples:
hellobot.cpp.

const char* SUETcpClientSession::InspectAddr   const [inline]
 

const char* SUETcpClientSession::InspectLocalAddr   const [inline]
 

int SUETcpClientSession::InspectLocalPort   const [inline]
 

int SUETcpClientSession::InspectPort   const [inline]
 

bool SUETcpClientSession::Up SUEEventSelector   a_selector,
const char *    src_ipaddr,
int    src_port
 

Start the session performing connect from the given address.

This version of the method calls socket(2), then bind(2), then connect(2), so that the connection is made from the given address.

bool SUETcpClientSession::Up SUEEventSelector   a_selector
 

Actually start the session.

The method calls socket(2), then tries to connect(2) to the desired destination. In case of success, registers the session and the timeout at the selector and returns true. In case socket(2) or connect(2) fails, immediately returns false

Examples:
hellobot.cpp.


The documentation for this class was generated from the following file:
Generated on Fri Feb 27 13:17:27 2004 for SUE Library by doxygen1.2.18