Results 1 to 9 of 9
  1. #1
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checking Internet state (VB6)

    Hi,

    Does anyone know of a method of detecting the state of the internet connection that checks at the time of checking, rather than when the app starts?

    I used the InternetGetConnected API method however, it seems to have a bit of a flaw:
    I'm connected to the internet over a Lan connection. I start my program and the app returns that I am connected. I pull the cable from the back of my machine. The app tells me I am still connected! I can't seem to find a method that checks the connection on the fly.

    Any help would be much appreciated.

    Regards,

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Checking Internet state (VB6)

    You mean InternetGetConnectedState? I assume you used a technique similar to the one Microsoft suggests in this article: How to determine the connection state of your local system and how to initiate or end an Internet connection by using Visual Basic .NET or Visual Basic 2005. If you click through to the API documentation, it indicates that at least one status that can be returned is "Local system has a valid connection to the Internet, but it might or might not be currently connected." You probably have to check one of the other ones, or more than one of them, to know for sure.

  3. #3
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checking Internet state (VB6)

    I'll keep looking. If I manage to find the flags to properly determine an active connection during runtime rather that when the application is executed i'll post my finding back here.
    In the mean time i've used a ping method, i'm not proud of it but it'll do until I work out the alternative.

    Regards,

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Checking Internet state (VB6)

    I would have thought that ping would be the only way to determine whether the connection was active at any point in time - otherwise the system would have to constantly test the network in some way to ensure that is was connected. This would be an system and network overhead that most programmers would want to avoid unless there was a good reason not to.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checking Internet state (VB6)

    I'm not entirely sure what the Wininet control does to check internet connectivity (i.e. does it check settings on the PC its running on or run a live test or something). I simply read the definition of what it was supposed to do and found that while it does do it, if you change the connection after you have launched the application, the API doesnt notice.

    I read a few comments on a Delphi site from people that were having the same problem. I only ended up there as I tried to widen by search my removing the "VB6" from it.

    Do you think the ping method is okay to use? Do website owners object to people randomly pinging their site at all?

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Checking Internet state (VB6)

    Phil,
    You can use the InternetCheckConnection API function, but as this basically attempts a ping to a host you specify, you might as well stick with what you've got! Just ping MS - they can't complain since it's the only option they gave you! <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checking Internet state (VB6)

    Valid point!

    If it was a program internal people were going to be using i'd have left it like it is without question, but as it is going to be used by reps from various companies I thought i'd best check that was normal practice before I released it.

    Thanks everyone for your input.

    Regards,

  8. #8
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Checking Internet state (VB6)

    This method on VBnet appears to do this without a ping - although how it works is a mystery to me.
    IsNetworkAlive

    If you do need to ping something, perhaps pinging the local dhcp would be better than hard coding in a particular website. DHCPServerAddress
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  9. #9
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checking Internet state (VB6)

    Thanks for the link Andrew. I'll be taking a look at that when I get a sec.

    Also, nice idea about the DHCP server address. If the link proves unsuccessful I'll have a look into using that.

Posting Permissions

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