Example documentation update
[senf.git] / Examples / UDPClientServer / Mainpage.dox
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \mainpage UDP Client/Server example application
24
25     \dontinclude udpServer.cc
26
27     This Application is a command line based client/server application, which sends some strings
28     from client to server, where they are printed on the command line.
29
30     After installing the Library, the udpServer and the udpClient can be found in the
31     senf/Example/udpServer directory and compiled with
32
33     <pre>
34     # scons -u
35     </pre>
36
37     Now you can start the application with
38     <pre>
39     # ./udpServer
40     # ./udpClient
41     </pre>
42
43     \section UDPserverApplication UDP server application
44
45     We take a look to the code starting with the Server: The file starts out including the necessary
46     header files:
47
48     \skip // Custom includes
49     \until membind
50
51     The Scheduler will be needed because we implement a non blocking UDP Server with the %senf
52     integrated Scheduler. The  scheduler library provides a simple yet flexible abstraction of
53     the standard asynchronous UNIX mainloop utilizing \c select or \c poll.
54
55     First we define a class which is responsible for opening a socket and print out the incoming
56     data on stdout. We create a \c ::UDPv4ClientSocketHandle, which is an unconnected and
57     uninitialized UDP (IPv4) socket.
58
59     \until serverSock;
60
61     The name \e client socket handle is a bit misleading: The handle is a \e client and not a \e
62     server socket handle since it implements the ordinary (client) socket API and not the connection
63     oriented (e.g. TCP accept) server socket API. Since UDP is not connection oriented, there exists
64     no \c UDPv4ServerSocketHandle.
65
66     \until {}
67
68     The constructor initialize the Server Object with a given address and port. In our case the
69     server configuration is static: The server listens on the loopback device on port 4243. We
70     instantiate and configure a senf::scheduler::FdEvent instance to call Server::readFromClient
71     whenever data is available on the handle.
72
73     \until }
74
75     The public \c run() member is called to run the sniffer. It enables the event callback and
76     enters the scheduler main-loop.
77
78     \until event)
79
80     This member function is called by the %scheduler whenever new data is available. The scheduler
81     passes in an event-mask of the event(s) triggering the call.
82
83     \until };
84
85     In the function the data from the socket is put into a standard string and dumped out on stdout.
86
87     \until return 0;
88     \until }
89
90     In the main function we need to create an Object of our Server with the loopback address and the
91     port.
92
93     That's it. We finish of by catching the exception and giving as much %detail as possible if an
94     exception is caught. The \c prettyName function from the \c Utils library is used, to get a
95     nice, printable representation of the dynamic type of the exception instance. It is an interface
96     to the g++ de-mangler. This is necessary since the name member of the C++ \c type_info instance
97     is a mangled name in g++.
98
99     \section UDPclientApplication UDP client application
100
101     \dontinclude udpClient.cc
102
103     The client application uses the same mechanisms but implements them in a small main function.
104     It sends numbers as strings to the server.
105
106     \skip  argv[])
107     \until return 0;
108     \until }
109
110     First a \c senf::::UDPv4ClientSocketHandle is created. With
111     <tt>writeto(senf::INet4SocketAddress, string)</tt> the string \c s will be written to the
112     specified address and port, which is constructed here from a static string read from the command
113     line with the syntax \c IP:PORT. In this example Integers from zero to ten are send to the
114     Server socket.
115 */
116
117 \f
118 // Local Variables:
119 // mode: c++
120 // fill-column: 100
121 // comment-column: 40
122 // c-file-style: "senf"
123 // indent-tabs-mode: nil
124 // ispell-local-dictionary: "american"
125 // compile-command: "scons -u test"
126 // mode: flyspell
127 // mode: auto-fill
128 // End: