Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Does QNetwork Reply works as Ping?
QtWS25 Last Chance

Does QNetwork Reply works as Ping?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 5.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alexandros
    wrote on 29 Nov 2012, 17:41 last edited by
    #1

    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!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on 29 Nov 2012, 18:57 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexandros
        wrote on 29 Nov 2012, 20:15 last edited by
        #3

        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 :)

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on 29 Nov 2012, 21:54 last edited by
          #4

          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"?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alexandros
            wrote on 12 Dec 2012, 21:34 last edited by
            #5

            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?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MuldeR
              wrote on 13 Dec 2012, 11:49 last edited by
              #6

              On Win32, we can use InternetGetConnectedState():
              http://msdn.microsoft.com/en-us/library/windows/desktop/aa384702(v=vs.85).aspx

              I'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...

              My OpenSource software at: http://muldersoft.com/

              Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

              Go visit the coop: http://youtu.be/Jay...

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                Zarko Markovic
                wrote on 13 Dec 2012, 13:08 last edited by
                #7

                [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.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Code_ReaQtor
                  wrote on 13 Dec 2012, 13:25 last edited by
                  #8

                  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".

                  Please visit my open-source projects at https://github.com/Code-ReaQtor.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MuldeR
                    wrote on 13 Dec 2012, 15:47 last edited by
                    #9

                    [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...

                    My OpenSource software at: http://muldersoft.com/

                    Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                    Go visit the coop: http://youtu.be/Jay...

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved