Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Classes
  • Files
  • File List
  • File Members

udpServer.cc

Go to the documentation of this file.
00001 // $Id: udpServer.cc 911 2008-09-19 14:03:55Z g0dil $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00023 // Custom includes
00024 #include <string>
00025 #include <senf/Socket/Protocols/INet.hh>
00026 #include <senf/Scheduler/Scheduler.hh>
00027 #include <senf/Utils/membind.hh>
00028 
00029 class Server
00030 {
00031     senf::UDPv4ClientSocketHandle serverSock;
00032     senf::scheduler::FdEvent event;
00033 
00034 public:
00035     Server(senf::INet4Address const & host, unsigned int port)
00036         : serverSock(senf::INet4SocketAddress(host, port)),
00037           event("UDPv4ClientServer", senf::membind(&Server::readFromClient, this),
00038                 serverSock, senf::scheduler::FdEvent::EV_READ, false)
00039         {}
00040 
00041     void run()
00042     {
00043         event.enable();
00044         senf::scheduler::process();
00045     }
00046 
00047 private:
00048     void readFromClient(int event)
00049     {
00050         std::string data (serverSock.read());
00051         std::cout << "> " << data<<std::endl ;
00052     }
00053 };
00054 
00055 int main(int argc, char const * argv[])
00056 {
00057     try {
00058         Server testSock(senf::INet4Address::Loopback, 4243);
00059         testSock.run();
00060     }
00061 
00062     catch (std::exception const & ex) {
00063         std::cerr << senf::prettyName(typeid(ex)) << ": " << ex.what() << "\n";
00064     }
00065     return 0;
00066 }
00067 
00068 
00069 // Local Variables:
00070 // mode: c++
00071 // fill-column: 100
00072 // comment-column: 40
00073 // c-file-style: "senf"
00074 // indent-tabs-mode: nil
00075 // ispell-local-dictionary: "american"
00076 // compile-command: "scons -u"
00077 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research