udpreceiver.h

00001 // Copyright (C) 2008,2009,2010 by Philipp Münzel. All rights reserved.
00002 // Released under the terms of the license described in license.txt
00003 
00004 #ifndef UDPRECEIVER_H
00005 #define UDPRECEIVER_H
00006 
00007 #include "dllexport.h"
00008 
00009 #include <boost/asio.hpp>
00010 #include <boost/bind.hpp>
00011 #include <boost/function.hpp>
00012 
00013 namespace SCS {
00014 
00023 class DLL_PUBLIC UDPReceiver
00024 {
00025 public:
00026 
00034     UDPReceiver(boost::function<void (void*, std::size_t)> function,
00035                 boost::asio::io_service& io_service,
00036                 const boost::asio::ip::address& address,
00037                 short port);
00038 
00042     ~UDPReceiver();
00043 
00044 
00045 private:
00046 
00047     typedef boost::asio::ip::udp::endpoint UDPEndpoint;
00048     typedef boost::asio::ip::udp::socket UDPSocket;
00049 
00055     void handle_receive_from(const boost::system::error_code& error,
00056                              std::size_t bytes_recvd);
00057 
00058     UDPEndpoint m_endpoint;
00059 
00060     UDPSocket m_socket;
00061 
00062     enum { max_length = 1440 }; 
00063 
00064     char data_[max_length];     
00065 
00069     boost::function<void (void*, std::size_t)> m_recv_fun;
00070 
00071     boost::asio::ip::address m_addr;
00072 
00073 };
00074 
00075 }
00076 
00077 #endif // UDPRECEIVER_H