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

SUETcpServer Class Reference

Generic TCP protocol server. More...

#include <sue_tcps.hpp>

Inheritance diagram for SUETcpServer:

Inheritance graph
[legend]
Collaboration diagram for SUETcpServer:

Collaboration graph
[legend]
List of all members.

Public Methods

 SUETcpServer (const char *a_ip, int a_port)
 Constructor.

virtual ~SUETcpServer ()
 Destructor.

bool Up (SUEEventSelector *a_selector)
 Bring the server up.

void Down ()
 Shut the server down.

unsigned long GetIpOfLastAccepted () const
 Get the ip address of the last accepted session.

void NotifySessionDown (SUETcpServerSession *sess)
 Session got down, kill its object.


Protected Methods

virtual SUETcpServerSessionSpawnSession (int newsessionfd)=0
 Method to create a custom SUETcpServerSession object.


Protected Attributes

SUEEventSelectorselector
 The Selector to use.


Detailed Description

Generic TCP protocol server.

This class implements a generic multiuser TCP server. It is inherited from SUEFdHandler because it has the descriptor for listening socket and handles its events. In order to create your own server, do the following:

Examples:

chat.cpp.


Constructor & Destructor Documentation

SUETcpServer::SUETcpServer const char *    a_ip,
int    a_port
 

Constructor.

The constructor. Parameters are:

Parameters:
a_ip  - the ip-address in the string representation, which you wish your server to bind to. Use "0.0.0.0" to bind to all addresses of your system.
a_port  - the TCP port to listen
Note:
constructor just constructs the object. It doesn't create a socket nor does it try to bind it or listen etc. See the Up() method.

virtual SUETcpServer::~SUETcpServer   [virtual]
 

Destructor.


Member Function Documentation

void SUETcpServer::Down  
 

Shut the server down.

This method removes the object from Selector, closes the listening socket and shuts down all active tcp sessions created by the server.

unsigned long SUETcpServer::GetIpOfLastAccepted  
 

Get the ip address of the last accepted session.

void SUETcpServer::NotifySessionDown SUETcpServerSession   sess
 

Session got down, kill its object.

This method is called by the SUETcpServerSession object when the session gets down. The method removes the Session object from the list of sessions and destroys the Session object calling delete sess;

Note:
This method is a part of internal communications. Forget it unless you'd like to modify the library itself.

virtual SUETcpServerSession* SUETcpServer::SpawnSession int    newsessionfd [protected, pure virtual]
 

Method to create a custom SUETcpServerSession object.

This method is called when a new request is accepted. It just creates an object of a subclass of SUETcpServerSession and returns a pointer to it. Override this method to create and return YOUR SUETcpServerSession object. For example,

      SUETcpServerSession* MyServer::SpawnSession(int fd)
      { return 
          new MySession(fd, timeout, selector, this, "MY GREETING\n");
      }
      
where selector and timeout are names of protected fields of SUETcpServer class.
Examples:
chat.cpp.

bool SUETcpServer::Up SUEEventSelector   a_selector
 

Bring the server up.

This method creates a socket to listen calling the socket(2) system call. Then it binds the socket to the ip address and port given to constructor of the object. After that, it calls listen(2) to listen the socket. In case everything's Ok, the method registers the object with the given Selector object to monitor the listening socket's activity. Method returns true if everything's Ok, or false if something went wrong.


Member Data Documentation

SUEEventSelector* SUETcpServer::selector [protected]
 

The Selector to use.


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