我正在尝试使用ios中的boost asio库连接dvr。该应用程序在ipv4网络中的模拟器中运行良好。但是当我在Appstore上提交应用程序时,苹果拒绝了该应用程序,因为它无法在ipv6网络上运行。我可以在苹果网站上看到应用程序应该支持ipv6网络。 https://developer.apple.com/news/?id=05042016a
所以我认为问题出现在我试图使用升级库连接到DVR的部分,其中DVR的IP地址是从DB(硬编码)中提取的,下面是代码的相关部分。
home.ts
start_connect方法
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_));
所以我很困惑如何更改上面的代码以便在IPV6网络上工作。无法在互联网上找到任何解决方案。
答案 0 :(得分:3)
您可以使用以下代码遍历端点以查找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;