CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    216

    How to detect if you are connected to internet?

    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. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150
    If you would have searched the forums first, you would have found the following function: InternetGetConnectedState
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Mar 2004
    Posts
    216

    thanks!!

    i looked it up in msdn (link) , 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?

    Code:
    	unsigned long *a;
    	a=(unsigned long *)malloc(sizeof(unsigned long));
    	if (TRUE==InternetGetConnectedState(a,0))
    		AfxMessageBox("online");
    	else
    		AfxMessageBox("offline");

  4. #4
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354
    Broadly speaking, there is no fool proof solution to your question. There was a long running threadDetecting an internet connection , with lots of solutions posted. You can choose one that is appropriate for you.
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

  5. #5
    Join Date
    Mar 2004
    Posts
    216
    thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured