Does QNetwork Reply works as Ping?
-
wrote on 29 Nov 2012, 17:41 last edited by
I am trying to avoid 'ping' in my program as a way to check for internet connection, because, sometimes it produces false positives.
Some routers prevent outgoing pings but allow any other type of traffic. I want with my program to download an image, thus pinging a remote server is not the best option to determine for internet connection.
Will a QNetwork reply (pointing to google) solve this problem?? Thanks a lot!
-
wrote on 29 Nov 2012, 18:57 last edited by
Why don't you just do what you want to do and handle there being no connection gracefully as it happens?
Even if you manage to download half the internet now, one second later the connection could be lost. So you need to handle failing downloads/uploads anyway.
-
wrote on 29 Nov 2012, 20:15 last edited by
I've thought of this, but I don't want to try to approach the server with the image without checking for internet connection, first.
I just need to know whether QNetworkReply works if outgoing pinging is disabled :)
-
wrote on 29 Nov 2012, 21:54 last edited by
Trying to access a website might work where ping fails. It might fail where ping works, too. Even if ping and http-access to google work: Your server might still be unreachable. There are really strange setups out there (think: Proxies configured to only allow access to whitelisted sites).
So what additional information do you get from "failing when doing something useless" that you can not get by "failing doing what you are supposed to do"?
-
wrote on 12 Dec 2012, 21:34 last edited by
Okay, let's say that you have a problem with the only task to check whether the PC is connected to the internet or not. What method would you use?
-
wrote on 13 Dec 2012, 11:49 last edited by
On Win32, we can use InternetGetConnectedState():
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384702(v=vs.85).aspxI'm not aware of an equivalent for Linux/Unix or a cross-platform alternative in Qt :-(
But what you can still do (and what I do too) is grabbing a list "known hosts", like from the well-known "Alexa":http://www.alexa.com/topsites/global list, and let your application try to connect to randomly selected hosts from that list. As soon as a certain minimum number of sites have answered correctly, you can be pretty sure that the Internet connection is up and working. If then your actual target host fails, it's probably because that host is down.
Note: Using a single host for your "connection" test (like google.com or a server of your own) is not a good idea, because whatever host you pick, it might be temporarily down or might not currently be reachable (or blocked) from the user's ISP or might not be available in the future! Also note that some hosts can be VERY slow from certain ISP's, so you better add a timeout to your check. I mean a timeout for the individual host...
-
wrote on 13 Dec 2012, 13:08 last edited by
[quote author="alexandros" date="1355348083"]Okay, let's say that you have a problem with the only task to check whether the PC is connected to the internet or not. What method would you use?[/quote]
The QNetworkConfigurationManager and it's signal onlineStateChanged.
-
wrote on 13 Dec 2012, 13:25 last edited by
Ping was based on "ICMP":http://en.wikipedia.org/wiki/Internet_Control_Message_Protocol .
Qt DOES NOT support this protocol.AFAIK, in the Windows SDK, there is a library called ICMP API that you can use for "ping".
-
wrote on 13 Dec 2012, 15:47 last edited by
[quote author="Zark" date="1355404107"][quote author="alexandros" date="1355348083"]Okay, let's say that you have a problem with the only task to check whether the PC is connected to the internet or not. What method would you use?[/quote]
The QNetworkConfigurationManager and it's signal onlineStateChanged.
[/quote]I think this would only check whether there is an active Network (LAN/WLAN) connection, but not whether we actually have Internet connectivity. If so, this could be used as the first step of the check (without Network connectiomn, we cannot have Internet), but this alone is not enough to ensure Internet connectivity. We mighte be in local Network with no Internet Gateway...