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