【问题标题】:Hole punching with boost::asio用 boost::asio 打孔
【发布时间】:2012-06-20 05:05:26
【问题描述】:

我尝试使用打孔协议制作服务器客户端。 所以我将我的客户端 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);

【问题讨论】:

  • 您需要发布一个可编译的小示例,以显示确切的问题。从您发布的摘录中很难理解问题可能出在哪里。

标签: c++ udp client-server hole-punching


【解决方案1】:

检查查询的参数。

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

我怀疑“Service not found Aborted”是指您的主机名看起来不像端口号或服务名称。

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

【讨论】:

    猜你喜欢
    • 2021-05-03
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多