How could I check whether device is online using Qt?
-
Is there any effective way to check whether a certain device is online, the device may vary from desktop to mobile devices.
By the way, I used QNetworkConfigurationManager::isOnline( ) to do this task, but unfortunately, when I closed my desktop connection ( Ubuntu 15.04 Enable network unchecked ), this function returned true as always, I bet because there was a lo ( loopback ) adapter is always active within my desktop, so it always returned true. -
Hi,
QNetworkConfigurationManager
manages your configuration not the remote one.
To detect if a device (network interface) is online you could use aping
message -
@mcosta Do I have to try to ping some site in order to get to know whether my device could get access to internet, right?
-
Will the devices also run a Qt app? If so, you could make the devices emit a heartbeat to indicate them being online.
-
@TheHawk Thanks, that's a way being able to keep alive when long connection is needed. There are several articles talking about TCP/IP heart beat, Do I need to do it myself, or there are existing heart beat API available?
-
I woulden't know actually. I think there will be one but why not make it yourself? It's not really complicated.
The slaves emit a certain data string to the master indicating them being alive once every 5 minutes for instance. The master keeps track of the slaves and knows when it doesn't receive anything from a slave after 5 mins its offline and perhaps could try to request its status in case the packet got lost or something similar.