[ACCEPTED]-boost::asio UDP broadcasting-broadcast
Accepted answer
Try the following code snippet to send a 2 UDP broadcast, utilizing the ba::ip::address_v4::broadcast()
call to get 1 an endpoint:
bs::error_code error;
ba::ip::udp::socket socket(_impl->_ioService);
socket.open(ba::ip::udp::v4(), error);
if (!error)
{
socket.set_option(ba::ip::udp::socket::reuse_address(true));
socket.set_option(ba::socket_base::broadcast(true));
ba::ip::udp::endpoint senderEndpoint(ba::ip::address_v4::broadcast(), port);
socket.send_to(data, senderEndpoint);
socket.close(error);
}
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.