boost asio resolver

asio 中的resolver一般用于将host等信息转化为socket信息,类似于getaddrinfo()

以下代码

    boost::asio::io_service io;
    tcp::resolver resolver(io);
    tcp::resolver::query query(boost::asio::ip::host_name(), "80");
    tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
    for (tcp::resolver::iterator iter; endpoint_iterator != iter; endpoint_iterator++)
    {
        std::cout << endpoint_iterator->endpoint() << std::endl;
    }

输出结果为:

[fe80::b085:5538:6305:667%13]:80
[fe80::c00c:b7bc:9c04:8ea6%18]:80
[fe80::144c:37dd:f5fc:e1a4%14]:80
10.3.30.91:80
192.168.1.150:80
192.168.128.1:80
[2001:0:9d38:953c:144c:37dd:f5fc:e1a4]:80

 

posted @ 2017-06-27 15:07  瓜蛋  阅读(1408)  评论(0编辑  收藏  举报