Results 1 to 5 of 5

Thread: [1.0/1.1] Detecting if there is an Internet Connection

  1. #1

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    [1.0/1.1] Detecting if there is an Internet Connection

    Hi. I usually detect if there is an internet connection by pinging a popular site like yahoo or google. However I was wondering if there is a neater way to determine if there is an internet connection, similar to MSN.

    From what i've noticed with msn is that as soon as an Internet connection is made active, msn signs in. That rules out some kind of thread, looks more like an event handler or something of that sort.

    Does anyone knows of a neat way to detect if an Internet connection is active?

    Jennifer.

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [1.0/1.1] Detecting if there is an Internet Connection

    You can use the InternetGetConnectedState API to determine if an internet connection is active.

    But using .NET you can use System.Net.NetworkInformation.NetworkChange method or there is some other SystemInformation.Network method.

    SystemInformation.Network Method:
    C# Code:
    1. bool ConState = SystemInformation.Network;
    2. if (ConState)
    3.  {
    4.      MessageBox.Show ("Connected");
    5.  }
    6.  else
    7.  {
    8.      MessageBox.Show ("No connection");
    9.  }
    Last edited by Paul M; Sep 23rd, 2007 at 05:49 AM.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [1.0/1.1] Detecting if there is an Internet Connection

    I believe MSN periodically attempts to ping an MSN server, although I might be wrong. I usually treat connectivity issues by assuming a connection is present and trapping an error in the case that it is not.

  4. #4

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] Detecting if there is an Internet Connection

    Thanks hell lord, it worked.

    Penegate, that's how i usually do it. However, i observed MSN and what i noticed is that if it's running in the background, not connected (since the internet connection) is down, and I start the internet connection, as soon as the internet connects, it detects it and signs in. It was just what I observed which made me suspect that its doing more that detecting if the connection exists at periodic intervals. I could be wrong, but its what i observed.

    Thank you very much for you help.

    Jennifer.

  5. #5
    Addicted Member corwin_ranger's Avatar
    Join Date
    Sep 2004
    Location
    CT
    Posts
    198

    Re: [1.0/1.1] Detecting if there is an Internet Connection

    Be carefule with SystemInformation.Network. It detects the presence of a Network Connection...ANY Network Connection. So, if you are in a corporate environment or on a home network, the state of this property will ALWAYS be true as long as your network is up. Even if your Internet connection is down.

    Steve

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