打孔与助推::asio

Hole punching with boost::asio

本文关键字:asio      更新时间:2023-10-16

我试图用打孔协议制作一个服务器客户端。所以我将我的客户端 IP 和客户端端口发送到我的服务器,当第二个用户连接时,服务器向两个客户端发送另一个客户端的 IP 和端口。所以当我有这个时,我试图在我的两个客户端之间建立连接,并且我在 boost::asio 时出错

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'

what(): 未找到服务中止

这是我的代码

std::vector<std::string> response;
response = split(reply, ':');
std::cout << "name : " << response[0] << std::endl;
std::cout << "adresse : " << response[1] << std::endl;
std::cout << "port : " << response[2] << std::endl;
udp::resolver::query query(udp::v4(), response[0], response[1]);
std::cout << "resolved - - -  -" << std::endl;
struct client *cl = new struct client();
cl->endpoint_iterator = resolver.resolve(query);
// It Crash HERE
cl->sender_endpoint = *endpoint_iterator;
cl->name = response[0];
_clients.push_back(cl);

检查查询的参数。

您正在打印响应 [1] 作为主机地址,将响应 [2] 打印为端口。但是您正在构造查询对象,其中响应 [0] 作为主机地址,响应 [1] 作为端口/服务。

我怀疑"找不到服务已中止"是指您的主机名看起来不像端口号或服务名称。

请参阅 http://www.boost.org/doc/libs/1_50_0/doc/html/boost_asio/reference/ip__basic_resolver_query/basic_resolver_query/overload4.html