shevek::server< client, serverdata >(3)

NAME
shevek::server< client, serverdata > - Set up a network server using shevek::telnet.

SYNOPSIS

#include <server.hh>

Inherits shevek::refbase.

  Classes

struct connection
Base of the client class which is implemented by the calling program.

  Public Types

typedef std::list< Glib::RefPtr< client > >::iterator iterator
Iterator for looping over all current connections.
typedef std::list< Glib::RefPtr< client > >::const_iterator const_iterator
Iterator for looping over all current connections.

  Public Member Functions

void open (std::string const &port, bool use_stdio=true)
Open a port and start running.
serverdata & data ()
Get the corresponding serverdata structure.
serverdata const & data () const
Get the corresponding serverdata structure.
iterator begin ()
Loop over all current connections.
iterator end ()
Loop over all current connections.
const_iterator begin () const
Loop over all current connections.
const_iterator end () const
Loop over all current connections.
void shutdown ()
Stop running this server, closing all current connections.
~server ()
The destructor shuts down the server.

  Static Public Member Functions

static Glib::RefPtr< server > create ()
Create a new server object.

  Additional Inherited Members

Detailed Description

  template<typename client, typename serverdata>class shevek::server< client, serverdata >
Set up a network server using shevek::telnet.

New connections are accepted, and callbacks to the program are made when a line of data is received.

An example file showing how to use the server:
 #include <shevek/server.hh>
 #include <shevek/mainloop.hh>

 // per-server data structure
 struct serverdata
 {
 // Put in here whatever you like, possibly nothing. There is one
 // instantiation of this class per server.
 // In most cases, global variables can be used instead of this class, but
 // this way allows programs to run more than one server of the same kind,
 // each with its own settings. That is a Good Thing.
 // It is available from server.data (), and therefore from
 // client->get_server ()->data ()
 };

 // Each object of this class is a connection. Add any members that are
 // needed on a per-connection basis in this class. Below is a very minimal
 // example, which implements an echo server (everything you write to it is
 // echoed back).
 class client : public shevek::server <client, serverdata>::connection<BR> {
 // Allow the server to call pickup and read.
 friend class shevek::server <client, serverdata>;
 void pickup (bool is_stdio)
 {
 out->write ('Welcome to the echo server.\\n');
 }
 void read (std::string const &line)
 {
 // An echo server should echo.
 out->write (line + '\n');
 }
 static Glib::RefPtr <client> create ()
 { return Glib::RefPtr <client> (new client () ); }
 // Make sure it cannot be constructed other than with create.
 // Don't use the constructor for initialising, use pickup () instead.
 // The connection is not initialised when the constructor is called.
 client () {}
 };

 int main ()
 {
 Glib::RefPtr <shevek::server <client, serverdata> >
 s = shevek::server <client, serverdata>::create ();
 // '1234' is the port to listen on. It may be a name from
 // /etc/services, such as 'telnet' (although you need to be root to claim
 // that one). It can also be a filename, which will be created as a unix
 // domain socket. Debugging is a little harder then, as netcat cannot
 // connect to such sockets.
 s->open ('1234');
 shevek::loop ();
 return 0;
 }

Member Function Documentation

  template<typename client , typename serverdata > void shevek::server< client, serverdata >::open (std::string const & port, bool use_stdio = true)

Open a port and start running. If use_stdio is true, there will be an initial connection from standard input/standard output.

Author

Generated automatically by Doxygen for libshevek from the source code.