i want use boost.asio create multicast udp sender. have thread , want use boost for:
socket;
send();
error handling;
can suggest something?
this relatively simple accomplish. here's basic class handles of need using synchronous calls:
#include <boost/asio.hpp> #include <boost/scoped_ptr.hpp> class multicastsender { public: multicastsender(const boost::asio::ip::address& multicast_addr, const unsigned short multicast_port) : ep_(multicast_addr, multicast_port) { socket_.reset(new boost::asio::ip::udp::socket(svc_, ep_.protocol())); } ~multicastsender() { socket_.reset(null); } public: void send_data(const std::string& msg) { socket_->send_to( boost::asio::buffer(msg.str()), ep_); } private: boost::asio::ip::udp::endpoint ep_; boost::scoped_ptr<boost::asio::ip::udp::socket> socket_; boost::asio::io_service svc_; };
this simple class meets 2 of 3 requirements (no error handling). use it, create instance of in appropriate place, , thread implementation calls multicastsender::send_data() send multicast data associated endpoint.
Comments
Post a Comment