【发布时间】:2016-09-05 07:15:19
【问题描述】:
我正在尝试使用 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 上找不到任何解决方案。
【问题讨论】:
-
resolver_.resolve()将迭代器返回到条目列表。您的代码只使用第一个条目。如果您遍历列表,您可能会找到一个 IPv6 条目... -
感谢回复,能否给我一些参考代码。
标签: ios objective-c boost boost-asio