C ++ Boost.Asio的平 [英] C++ Boost.asio Ping

查看:213
本文介绍了C ++ Boost.Asio的平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个程序,将列出所有设备的IP地址,在网络上。
之一的这个主要部件是能够执行ping设备。
该程序必须在Linux,Windows和Mac的工作,所以我选择了Boost库。

I'm trying to make a program that will list all of the IP addresses of devices on a network. One of the main components of this is being able to ping devices. This program must work on Linux, Windows and Mac, so I chose the Boost library.

我设法找到的文档在这个例子:
http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/example/icmp/ping.cpp

I managed to find this example in the documentation: http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/example/icmp/ping.cpp

我位于C相当有经验++使用OpenGL 3.1和明暗器时,但是当我运行这个程序,它坪遍地(454+),并理解它是扔我一个循环(没有双关语意),它似乎包含速记的大量的,功能我从来没有见过等等。

I am fairly experienced at C++ when using OpenGL 3.1 and Shaders but when I run this program it pings over and over (454+) and understanding it is throwing me for a loop (No pun intended) , it seems to contain a substantial amount of shorthand, functions I've never seen etc.

有没有更简单的ping一台机器升压方法:ASIO?
或者有没有办法我能得到这个方法来运行只有4次,并返回的平均响应时间?

Is there a simpler method to ping a machine with Boost:asio? or Is there a way I can get this method to run just 4 times and return the average response time?

推荐答案

在链接的例子中,你必须更改 handle_receive 功能包括一个计数器。当它被调用四次你告诉 io_server 对象来停止(对于这一点,你要么拥有使其全球性的,或参考存储它在瓶儿类),而不是叫 start_receive

In the linked example you have to change the handle_receive function to include a counter. When it has been called four times you tell the io_server object to stop (for this you either has to make it global, or store a reference to it in the pinger class) and not call start_receive.

这篇关于C ++ Boost.Asio的平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆