4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the
19 // Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // Definition of non-inline non-template functions
24 //#include "server.hh"
25 //#include "server.ih"
30 #include "Scheduler/Scheduler.hh"
31 #include "Utils/membind.hh"
32 #include "Socket/Protocols/INet/TCPSocketHandle.hh"
33 #include "Socket/Protocols/INet/INetAddressing.hh"
38 senf::TCPv4ServerSocketHandle serverSock;
41 Server(std::string const & host, unsigned int port)
42 : serverSock(senf::INet4Address(host, port)) {}
46 senf::Scheduler::instance().add(
48 senf::membind(&Server::accept, this),
49 senf::Scheduler::EV_READ);
50 senf::Scheduler::instance().process();
54 void accept(senf::FileHandle /* ignored */, senf::Scheduler::EventId event)
56 senf::TCPv4ClientSocketHandle clientSock (serverSock.accept());
57 senf::Scheduler::instance().add(
59 senf::membind(&Server::readFromClient, this),
60 senf::Scheduler::EV_READ);
63 void readFromClient(senf::TCPv4ClientSocketHandle clientSock, senf::Scheduler::EventId event)
66 senf::Scheduler::instance().remove(clientSock);
69 std::string data (clientSock.read());
70 std::cout << "'" << data << "'" << std::endl;
75 int main(int argc, char const * argv[])
78 Server myServer ("127.0.0.1", 4243);
81 catch (std::exception const & ex) {
82 std::cerr << senf::prettyName(typeid(ex)) << ": " << ex.what() << "\n";