我想使用UDP广播到本地网络中的所有计算机boost::asio.通过实例我想出了
try {
socket.open(boost::asio::ip::udp::v4());
boost::asio::socket_base::broadcast option(true);
socket.set_option(option);
endpoint = boost::asio::ip::udp::endpoint(
boost::asio::ip::address::from_string("192.168.1.255"),
port);
}
catch(std::exception &e) {
}
Run Code Online (Sandbox Code Playgroud)
并希望用我的队列广播消息
while(!queue.empty()) {
std::string message = queue.front();
boost::system::error_code ignored_error;
socket.send_to(
boost::asio::buffer(message),
endpoint,
0, ignored_error);
queue.pop_front();
}
Run Code Online (Sandbox Code Playgroud)
但是我的代码invalid argument在第一个代码块中引发异常异常.127.0.0.1虽然它工作正常.我究竟做错了什么?