我正在使用Boost Asio進行跨平臺聯網。我嘗試了各種連接方法,並在嘗試連接到Android上的套接字時不斷收到「Element not found」asio.misc錯誤。我很困惑,因爲這是在成功解析域名後發生的。例如,如果我爲主機和端口80輸入google.com,那麼解析器將打印出所有20個以上的Google服務器,但之後它將不會連接說asio.misc「找不到元素」加速Android Asio連接錯誤
這是我的代碼:
boost::asio::io_service service;
boost::system::error_code ec;
boost::asio::ip::tcp::resolver resolver(service);
boost::asio::ip::tcp::resolver::query query(host, port);
boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query, ec);
boost::asio::ip::tcp::resolver::iterator iterEnd;
boost::asio::ip::tcp::endpoint ep;
int it = 0;
while(iter != iterEnd)
{
ep = *iter++;
debug+="\nLooking at resolve with address " + ep.address().to_string();
it++;
}
//Try to connect through asio
boost::asio::ip::tcp::socket sock(service);
//asio::connect does all the iterator work for us.
boost::asio::connect(sock, iter, ec);
if(ec)
{
return new string("Should be connected but I can't");
}
else
{
debug+= "\n " + ec.message() + "\n " + ec.category().name();
return debug;
}
你有訪問互聯網所需的權限? – sehe
是的,我願意。它將域名解析爲正確的IP地址,所以我知道我設置了它。 – Theopile
你打電話給'服務'? ** post()**或** bind()**。 –