【发布时间】:2023-03-09 00:23:01
【问题描述】:
我已经尝试使用来自 boost 文档 (http://www.boost.org/doc/libs/1_58_0/doc/html/boost_asio/tutorial/tutdaytime4/src.html) 的同步 UDP 客户端的示例代码,我只删除了示例的“发送”部分:
#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
using boost::asio::ip::udp;
int main(int argc, char* argv[])
{
try
{
boost::asio::io_service io_service;
udp::socket socket(io_service);
socket.open(udp::v4());
boost::array<char, 128> recv_buf;
udp::endpoint sender_endpoint;
size_t len = socket.receive_from(
boost::asio::buffer(recv_buf), sender_endpoint); // Causes the exception "An invalid argument was supplied".
std::cout.write(recv_buf.data(), len);
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}
我没有对示例代码进行任何其他更改,我也没有发现它有任何问题,那么为什么会创建异常呢?我没有激活防火墙,它可能会阻止任何东西。
【问题讨论】:
标签: boost udp client windows-8.1 boost-asio