4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
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
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.
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.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Thorsten Horstmann <tho@berlios.de>
29 // Definition of non-inline non-template functions
31 //#include "server.hh"
32 //#include "server.ih"
37 #include <senf/Scheduler/Scheduler.hh>
38 #include <senf/Utils/membind.hh>
39 #include <senf/Socket/Protocols/INet.hh>
43 senf::TCPv4ServerSocketHandle serverSock;
44 senf::scheduler::FdEvent acceptevent;
45 senf::scheduler::FdEvent readevent;
48 Server(senf::INet4Address const & host, unsigned int port)
49 : serverSock(senf::INet4SocketAddress(host, port)),
50 acceptevent("Server accept", senf::membind(&Server::accept, this),
51 serverSock, senf::scheduler::FdEvent::EV_READ),
52 readevent("Server read", 0)
57 senf::scheduler::process();
61 void accept(int event)
63 senf::TCPv4ClientSocketHandle clientSock (serverSock.accept());
65 .action(boost::bind(&Server::readFromClient, this, clientSock, _1))
67 .events(senf::scheduler::FdEvent::EV_READ)
71 void readFromClient(senf::TCPv4ClientSocketHandle clientSock, int event)
77 std::string data (clientSock.read());
78 std::cout << "'" << data << "'" << std::endl;
83 int main(int argc, char const * argv[])
86 Server myServer (senf::INet4Address::Loopback, 4243);
89 catch (std::exception const & ex) {
90 std::cerr << senf::prettyName(typeid(ex)) << ": " << ex.what() << "\n";
99 // c-file-style: "senf"
100 // indent-tabs-mode: nil
101 // ispell-local-dictionary: "american"
102 // compile-command: "scons -u"
103 // comment-column: 40