Would like to say Hello to all as I’ve just joined the
list today and am also a first time user of the boost libraries.
I’m cutting my teeth on asio by trying to receive a
UDP multicast message with the boost::asio::ip::udp::socket::receive_from
function.
I got it going using the windows calls but just cant seem to
crack it with boost. My only suspicion is that im getting the wrong IP version
in the endpoint, but would guess it has found it from the initialisation, but
other than that im a bit stumped.
Any suggestions to where I may be going wrong?
Cheers
David
Heres the code:
const
boost::asio::ip::address listen_address =
boost::asio::ip::address::from_string("192.168.1.1");
const
boost::asio::ip::address multicast_address =
boost::asio::ip::address::from_string("224.x.x.x");
//appropriate address used
boost::asio::io_service
io_service;
boost::asio::ip::udp::socket
socket_(io_service);
boost::asio::ip::udp::endpoint
sender_endpoint_;
enum { max_length =
1024 };
char
data_[max_length];
// Create the
endpoint
boost::asio::ip::udp::endpoint
listen_endpoint(
listen_address,
multicast_port);
// open the socket
socket_.open(listen_endpoint.protocol());
// is this picking up v6 instead of v4?
// Join the
multicast group.
socket_.set_option(
boost::asio::ip::multicast::join_group(multicast_address));
// bind it
socket_.bind(listen_endpoint);
socket_.receive_from(
boost::asio::buffer(data_,
max_length),
sender_endpoint_);