switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / Examples / UDPClientServer / Mainpage.dox
index b35b642..ab4d725 100644 (file)
-// $Id: Mainpage.dox 625 2008-01-16 12:00:00Z Pug $
+// $Id$
 //
-// Copyright (C) 2007 
-// Fraunhofer Institute for Open Communication Systems (FOKUS) 
-// Competence Center NETwork research (NET), St. Augustin, GERMANY 
-//     Stefan Bund <g0dil@berlios.de>
+// Copyright (C) 2008
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
 //
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at 
+// http://senf.berlios.de/license.html
 //
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
+// The Fraunhofer FOKUS Public License Version 1.0 is based on, 
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
 //
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+// Software distributed under the License is distributed on an "AS IS" basis, 
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+//
+// Contributor(s):
+//   Stefan Bund <g0dil@berlios.de>
+
 
-/** \mainpage UDP Client/Server example application 
+/** \mainpage UDP Client/Server example application
 
     \dontinclude udpServer.cc
 
-    This Application is a command line based client/server application, which sends some strings from
-    client to server, where they are printed on the command line.
+    This Application is a command line based client/server application, which sends some strings
+    from client to server, where they are printed on the command line.
 
-    After installing the Library,  the udpServer and the udpClient can be found in the 
-    senf/Example/udpServer directory and compiled with 
+    After installing the Library, the udpServer and the udpClient can be found in the
+    senf/Example/udpServer directory and compiled with
 
     <pre>
-        #scons -u
-        <Then you can start the client/server with>
+    # scons -u
+    </pre>
 
-        #./udpServer
-        #./udpClient
+    Now you can start the application with
+    <pre>
+    # ./udpServer
+    # ./udpClient
     </pre>
 
-    When we take a look to the code, we start with the Server: 
-    First we include the necessary headers: 
+    \section UDPserverApplication UDP server application
+
+    We take a look to the code starting with the Server: The file starts out including the necessary
+    header files:
 
     \skip // Custom includes
     \until membind
 
-    The Scheduler will be needed because we implement a non blocking UDP Server with the %senf 
-    integrated Scheduler. The  scheduler library provides a simple yet flexible abstraction of 
+    The Scheduler will be needed because we implement a non blocking UDP Server with the %senf
+    integrated Scheduler. The  scheduler library provides a simple yet flexible abstraction of
     the standard asynchronous UNIX mainloop utilizing \c select or \c poll.
 
-    \section UDP_serverApplication UDP server application
-
     First we define a class which is responsible for opening a socket and print out the incoming
-    data on stdout. We create a \c UDPv4ClientSocketHandle, which is an unconnected and
-    uninitialized UDP (Ipv4) socket.
+    data on stdout. We create a \c ::UDPv4ClientSocketHandle, which is an unconnected and
+    uninitialized UDP (IPv4) socket.
 
     \until serverSock;
 
-    The constructor initialize the Server Object with a given address and port. In our case the
-    server listens static on the loopback device with port 4243.
+    The name \e client socket handle is a bit misleading: The handle is a \e client and not a \e
+    server socket handle since it implements the ordinary (client) socket API and not the connection
+    oriented (e.g. TCP accept) server socket API. Since UDP is not connection oriented, there exists
+    no \c UDPv4ServerSocketHandle.
 
     \until {}
 
-    The public \c run() member is called to run the sniffer. It first adds the socket to the 
-    Scheduler. The \c add() call takes two Arguments, the socket to bind to (which can be a 
-    lot of things and must not necessarily be a socket instance) and callback function to call, 
-    whenever there is an event on that socket.The callback is specified as a
-    <a href="http://www.boost.org/doc/html/function.html">Boost.Function</a> object. A third
-    argument may be specified to restrict the events, on which the function is called, here we
-    used the EV_READ Argument, because we just want the program to read from the socket.
-    The default argument is set to \c senf::Scheduler::EV_ALL, which allows all actions on the socket.
+    The constructor initialize the Server Object with a given address and port. In our case the
+    server configuration is static: The server listens on the loopback device on port 4243. We
+    instantiate and configure a senf::scheduler::FdEvent instance to call Server::readFromClient
+    whenever data is available on the handle.
 
     \until }
 
-    Calling the Schedulers \c process() method will start the event loop. This call does not 
-    return (ok, it does return in special cases if \c senf::Scheduler::terminate() is called which
-    does not apply here). The Callback Function is the \c readFromClient() Function, which is 
-    declared as private here and will be called whenever an event on the socket is encountered.
-    The scheduler passes the event ID to the function.
+    The public \c run() member is called to run the sniffer. It enables the event callback and
+    enters the scheduler main-loop.
 
     \until event)
 
-    In the function the data from the socket is put into a standard string and dumped out on stdout. 
+    This member function is called by the %scheduler whenever new data is available. The scheduler
+    passes in an event-mask of the event(s) triggering the call.
 
     \until };
 
-    In the main function we need to create an Object of our Server with the loopback address and the port.
+    In the function the data from the socket is put into a standard string and dumped out on stdout.
 
     \until return 0;
+    \until }
+
+    In the main function we need to create an Object of our Server with the loopback address and the
+    port.
 
-    That's it. We finish of by catching the exception and giving as much detail as possible if an 
-    exception is caught. The \c prettyName function from the \c Utils library is used, to get a nice,
-    printable representation of the dynamic type of the exception instance. It is an interface to 
-    the g++ demangler. This is necessary since the name member of the C++ \c type_info instance is 
-    a mangled name in g++.
+    That's it. We finish of by catching the exception and giving as much %detail as possible if an
+    exception is caught. The \c prettyName function from the \c Utils library is used, to get a
+    nice, printable representation of the dynamic type of the exception instance. It is an interface
+    to the g++ de-mangler. This is necessary since the name member of the C++ \c type_info instance
+    is a mangled name in g++.
+
+    \section UDPclientApplication UDP client application
 
-    \section UDP_clientApplication UDP client application
-    
     \dontinclude udpClient.cc
 
-    The client application uses the same mechanisms, but implements them in a small main function. 
-    It sends numbers as strings to the server. 
+    The client application uses the same mechanisms but implements them in a small main function.
+    It sends numbers as strings to the server.
 
     \skip  argv[])
     \until return 0;
+    \until }
 
-    First a \c UDPv4ClientSocketHandle is created. With the function 
-    \c writeto(senf::INet4SocketAddress, string) the string s will be written to the specified
-    address and port, which is constructed here from a  static string \c "127.0.0.1:4243". In this
-    example Integers from zero to ten are send to the Server socket. 
-
-    The exception handling is again the same as with the server application.
+    First a \c senf::::UDPv4ClientSocketHandle is created. With
+    <tt>writeto(senf::INet4SocketAddress, string)</tt> the string \c s will be written to the
+    specified address and port, which is constructed here from a static string read from the command
+    line with the syntax \c IP:PORT. In this example Integers from zero to ten are send to the
+    Server socket.
 */
 
-
+\f
 // Local Variables:
 // mode: c++
 // fill-column: 100