C++ Boost.asio Ping

戏子无情 提交于 2019-12-06 10:46:49

问题


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.

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

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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/11998746/c-boost-asio-ping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!