Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to detect if you are connected to internet?

How to detect if you are connected to internet?

Scheduled Pinned Locked Moved C / C++ / MFC
c++sysadminjsontutorialquestion
9 Posts 6 Posters 0 Views 1 Watching
  • 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.
  • K Offline
    K Offline
    kfaday
    wrote on last edited by
    #1

    Hi, i'm creating a jabber client (a chat tool, like icq or msn). In the app, i send info to a server, and i receive from it. I use MFC CSocket. Is there any api function that checks if you are connected to internet? thanks!!!

    2 D M 3 Replies Last reply
    0
    • K kfaday

      Hi, i'm creating a jabber client (a chat tool, like icq or msn). In the app, i send info to a server, and i receive from it. I use MFC CSocket. Is there any api function that checks if you are connected to internet? thanks!!!

      2 Offline
      2 Offline
      224917
      wrote on last edited by
      #2

      InternetGetConnectedState


      It's not a bug, it's an undocumented feature.
      suhredayan@omniquad.com

      messenger :suhredayan@hotmail.com

      K 1 Reply Last reply
      0
      • 2 224917

        InternetGetConnectedState


        It's not a bug, it's an undocumented feature.
        suhredayan@omniquad.com

        messenger :suhredayan@hotmail.com

        K Offline
        K Offline
        kfaday
        wrote on last edited by
        #3

        thanks! i looked it up in msdn ( http://msdn.microsoft.com/library/?url=/library/en-us/wininet/wininet/internetgetconnectedstate.asp) , and i don't understand the following: lpdwFlags [out] Pointer to a variable that receives the connection description. This parameter can be one or more of the following values. Value Meaning INTERNET_CONNECTION_CONFIGURED Local system has a valid connection to the Internet, but it might or might not be currently connected. INTERNET_CONNECTION_LAN Local system uses a local area network to connect to the Internet. INTERNET_CONNECTION_MODEM Local system uses a modem to connect to the Internet. INTERNET_CONNECTION_MODEM_BUSY No longer used. INTERNET_CONNECTION_OFFLINE Local system is in offline mode. INTERNET_CONNECTION_PROXY Local system uses a proxy server to connect to the Internet. INTERNET_RAS_INSTALLED Local system has RAS installed. the following code always returns online.. any ideas?

        unsigned long \*a;
        a=(unsigned long \*)malloc(sizeof(unsigned long));
        if (TRUE==InternetGetConnectedState(a,0))
        	AfxMessageBox("online");
        else
        	AfxMessageBox("offline");
        
        1 Reply Last reply
        0
        • K kfaday

          Hi, i'm creating a jabber client (a chat tool, like icq or msn). In the app, i send info to a server, and i receive from it. I use MFC CSocket. Is there any api function that checks if you are connected to internet? thanks!!!

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          kfaday wrote: I use MFC CSocket. Over CAsyncSocket? Why? kfaday wrote: Is there any api function that checks if you are connected to internet? See here.


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          V 1 Reply Last reply
          0
          • D David Crow

            kfaday wrote: I use MFC CSocket. Over CAsyncSocket? Why? kfaday wrote: Is there any api function that checks if you are connected to internet? See here.


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            V Offline
            V Offline
            vcplusplus
            wrote on last edited by
            #5

            Check out this article http://tangentsoft.net/wskfaq/articles/csocket.html

            D 1 Reply Last reply
            0
            • V vcplusplus

              Check out this article http://tangentsoft.net/wskfaq/articles/csocket.html

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              And your point is? I'm aware of the downfalls of using CSocket, some of which aren't even mentioned in your article, but perhaps the OP is not.


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              1 Reply Last reply
              0
              • K kfaday

                Hi, i'm creating a jabber client (a chat tool, like icq or msn). In the app, i send info to a server, and i receive from it. I use MFC CSocket. Is there any api function that checks if you are connected to internet? thanks!!!

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #7

                See the FAQ 8.7 How do I tell if the computer is connected to the Internet?[^] --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "Just because the box has 2 gigabytes of memory doesn't mean you get to use it all!"   -- Rico Mariani, CLR perf guy

                P K 2 Replies Last reply
                0
                • M Michael Dunn

                  See the FAQ 8.7 How do I tell if the computer is connected to the Internet?[^] --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "Just because the box has 2 gigabytes of memory doesn't mean you get to use it all!"   -- Rico Mariani, CLR perf guy

                  P Offline
                  P Offline
                  palbano
                  wrote on last edited by
                  #8

                  You know what would be great is if you could search for stuff on the internet instead of waiting for some nice person like you to provide a link to the page(s) of interest. :omg::zzz: But, that's just my opinion... I could be wrong.

                  1 Reply Last reply
                  0
                  • M Michael Dunn

                    See the FAQ 8.7 How do I tell if the computer is connected to the Internet?[^] --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "Just because the box has 2 gigabytes of memory doesn't mean you get to use it all!"   -- Rico Mariani, CLR perf guy

                    K Offline
                    K Offline
                    kfaday
                    wrote on last edited by
                    #9

                    thanks for the link to the faq

                    #include .
                    .
                    .

                    BOOL bConnected;
                    DWORD dwFlags;

                    bConnected = InternetGetConnectedState ( &dwFlags, 0 );

                    if ( bConnected )
                    if ( dwFlags & INTERNET_CONNECTION_OFFLINE )
                    bConnected = FALSE;

                    i get this error: error C2065: 'INTERNET_CONNECTION_OFFLINE' : undeclared identifier any ideas? thanks!

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups