Boost::Asio 序列: 域名解析

被刻印的时光 ゝ 提交于 2020-04-12 16:59:25
// #include <QCoreApplication>
/*
 * ModuleName: Main
 * Description: Boost::asio::ip::tcp::resolver
 * Author: hsw
 * Date: 2020-04-11
 *
 */

#include <iostream>
#include <boost/asio.hpp>

using boost::asio::ip::udp;
using boost::asio::ip::tcp;

int main(int argc, char *argv[])
{
    boost::asio::io_context ioContext;

    tcp::resolver ioResolver(ioContext);

    tcp::resolver::query ioQuery(boost::asio::ip::tcp::v4(), "www.cnblogs.com", "https");
    boost::system::error_code ec;
    tcp::resolver::results_type ioResults = ioResolver.resolve(ioQuery, ec);

    if(ec)
    {
        std::cout << "e = " << ec.message() << std::endl;
        return -1;
    }


    std::cout << "ioResults Count = " << ioResults.size() << std::endl;
    for(tcp::resolver::iterator iter = ioResults.begin(); iter != ioResults.end(); ++iter)
    {
        std::cout << "iter = " << iter->endpoint().address().to_string() << std::endl;
    }

    return 0;
}

发布了203 篇原创文章 · 获赞 109 · 访问量 32万+
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!