.TH "shevek::server< client, serverdata >" 3 "Wed Jul 9 2014" "libshevek" \" -*- nroff -*- .ad l .nh .SH NAME shevek::server< client, serverdata > \- .PP Set up a network server using \fBshevek::telnet\fP\&. .SH SYNOPSIS .br .PP .PP \fC#include \fP .PP Inherits \fBshevek::refbase\fP\&. .SS "Classes" .in +1c .ti -1c .RI "struct \fBconnection\fP" .br .RI "\fIBase of the client class which is implemented by the calling program\&. \fP" .in -1c .SS "Public Types" .in +1c .ti -1c .RI "typedef std::list .br < Glib::RefPtr< client > .br >::\fBiterator\fP \fBiterator\fP" .br .RI "\fIIterator for looping over all current connections\&. \fP" .ti -1c .RI "typedef std::list .br < Glib::RefPtr< client > .br >::\fBconst_iterator\fP \fBconst_iterator\fP" .br .RI "\fIIterator for looping over all current connections\&. \fP" .in -1c .SS "Public Member Functions" .in +1c .ti -1c .RI "void \fBopen\fP (std::string const &port, bool use_stdio=true)" .br .RI "\fIOpen a port and start running\&. \fP" .ti -1c .RI "serverdata & \fBdata\fP ()" .br .RI "\fIGet the corresponding serverdata structure\&. \fP" .ti -1c .RI "serverdata const & \fBdata\fP () const " .br .RI "\fIGet the corresponding serverdata structure\&. \fP" .ti -1c .RI "\fBiterator\fP \fBbegin\fP ()" .br .RI "\fILoop over all current connections\&. \fP" .ti -1c .RI "\fBiterator\fP \fBend\fP ()" .br .RI "\fILoop over all current connections\&. \fP" .ti -1c .RI "\fBconst_iterator\fP \fBbegin\fP () const " .br .RI "\fILoop over all current connections\&. \fP" .ti -1c .RI "\fBconst_iterator\fP \fBend\fP () const " .br .RI "\fILoop over all current connections\&. \fP" .ti -1c .RI "void \fBshutdown\fP ()" .br .RI "\fIStop running this server, closing all current connections\&. \fP" .ti -1c .RI "\fB~server\fP ()" .br .RI "\fIThe destructor shuts down the server\&. \fP" .in -1c .SS "Static Public Member Functions" .in +1c .ti -1c .RI "static Glib::RefPtr< \fBserver\fP > \fBcreate\fP ()" .br .RI "\fICreate a new server object\&. \fP" .in -1c .SS "Additional Inherited Members" .SH "Detailed Description" .PP .SS "templateclass shevek::server< client, serverdata >" Set up a network server using \fBshevek::telnet\fP\&. New connections are accepted, and callbacks to the program are made when a line of data is received\&. .PP An example file showing how to use the server: \fC .br #include .br #include .br .br // per-server data structure .br struct serverdata .br { .br // Put in here whatever you like, possibly nothing\&. There is one .br // instantiation of this class per server\&. .br // In most cases, global variables can be used instead of this class, but .br // this way allows programs to run more than one server of the same kind, .br // each with its own settings\&. That is a Good Thing\&. .br // It is available from \fBserver\&.data\fP (), and therefore from .br // client->get_server ()->data () .br }; .br .br // Each object of this class is a connection\&. Add any members that are .br // needed on a per-connection basis in this class\&. Below is a very minimal .br // example, which implements an echo server (everything you write to it is .br // echoed back)\&. .br class client : public \fBshevek::server\fP ::connection
{ .br // Allow the server to call pickup and read\&. .br friend class \fBshevek::server\fP ; .br void pickup (bool is_stdio) .br { .br out->write ('Welcome to the echo server\&.\\\\n'); .br } .br void read (std::string const &line) .br { .br // An echo server should echo\&. .br out->write (line + '\\n'); .br } .br static Glib::RefPtr create () .br { return Glib::RefPtr (new client () ); } .br // Make sure it cannot be constructed other than with create\&. .br // Don't use the constructor for initialising, use pickup () instead\&. .br // The connection is not initialised when the constructor is called\&. .br client () {} .br }; .br .br int main () .br { .br Glib::RefPtr <\fBshevek::server\fP > .br s = \fBshevek::server\fP ::create (); .br // '1234' is the port to listen on\&. It may be a name from .br // /etc/services, such as 'telnet' (although you need to be root to claim .br // that one)\&. It can also be a filename, which will be created as a unix .br // domain socket\&. Debugging is a little harder then, as netcat cannot .br // connect to such sockets\&. .br s->open ('1234'); .br shevek::loop (); .br return 0; .br } .br \fP .SH "Member Function Documentation" .PP .SS "template void \fBshevek::server\fP< client, serverdata >::open (std::string const &port, booluse_stdio = \fCtrue\fP)" .PP Open a port and start running\&. If use_stdio is true, there will be an initial connection from standard input/standard output\&. .SH "Author" .PP Generated automatically by Doxygen for libshevek from the source code\&.