gpt4 book ai didi

IOS boost asio 从 ipv6 网络连接

转载 作者:技术小花猫 更新时间:2023-10-29 11:06:36 24 4
gpt4 key购买 nike

我正在尝试使用 ios 中的 boost asio 库连接 dvr。该应用程序在 ipv4 网络的模拟器中运行良好。但是当我在 Appstore 上提交应用程序时,苹果拒绝了该应用程序,因为它不能在 ipv6 网络上运行。我可以在苹果网站上看到应用程序应该支持 ipv6 网络。 https://developer.apple.com/news/?id=05042016a

所以我认为问题出在我尝试使用 boost 库连接到 DVR 的部分,其中 DVR 的 IP 地址是从 DB(硬编码)中提取的,下面是代码的相关部分。

        boost::asio::io_service io_service_;
tcp::resolver::iterator endpoint_iter_;
tcp::resolver resolver_; //to healp resolving hostname and ip

stringstream strstream;//create a stringstream
strstream << port;//add number to the stream

endpoint_iter_ = resolver_.resolve(tcp::resolver::query(ip.c_str(),strstream.str()));
start_connect(endpoint_iter_);

// Start the deadline actor. You will note that we're not setting any
// particular deadline here. Instead, the connect and input actors will
// update the deadline prior to each asynchronous operation.
deadline_timer_.async_wait(boost::bind(&dvr_obj::check_deadline, this));
//starting thread for dvr connection
io_service_.reset();
thread_ = new boost::thread(boost::bind(&boost::asio::io_service::run, &io_service_));

start_connect 方法

void start_connect(tcp::resolver::iterator endpoint_iter)
{
try
{
if (endpoint_iter != tcp::resolver::iterator())
{

drill_debug_info("trying to connect %s \n",name.c_str());

// Set a deadline for the connect operation.
deadline_timer_.expires_from_now(boost::posix_time::seconds(10));

// Start the asynchronous connect operation.
socket_.async_connect(endpoint_iter->endpoint(),
boost::bind(&dvr_obj::handle_connect,
this, _1, endpoint_iter));
}
else
{
// There are no more endpoints to try. Shut down the client.

connectivity = false;
}
} catch (int e) {

connectivity = false;
}
}

所以我很困惑如何更改上面的代码以在 IPV6 网络上工作。无法在 Internet 上找到任何解决方案。

最佳答案

您可以使用以下代码遍历端点以查找 IPv6 端点:

endpoint_iter_ = resolver_.resolve(tcp::resolver::query(ip.c_str(),strstream.str()));

while (endpoint_iter_ != tcp::resolver::iterator())
{
if (endpoint_iter_->endpoint().protocol() == tcp::v6())
break;
++endpoint_iter_;
}

if (endpoint_iter_ != tcp::resolver::iterator())
{
start_connect(endpoint_iter_);
...
}
else
std::cerr << "IPv6 host not found" << std::endl;

关于IOS boost asio 从 ipv6 网络连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39325504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com