Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WinInet InternetCheckConnection and InternetGetConnectedState

533 views
Skip to first unread message

Joe H

unread,
Jan 29, 2008, 11:34:20 AM1/29/08
to
I' searched for more than an hour and the newest post I've seen on this
is 2003. I can't find anything in any of the winapi or winsock area and
most of the references I do find are on the defunct winapi group.
Hopefully someone can enlighten me.

I'm trying to verify an Internet connection is available before trying
to do some things. It seems InternetGetConnectedState works but I've
seen a number of posts that claim it is not reliable because if the
Internet is turned off it will supposedly still show it as available.
Anyway I would hope that four years later that things have improved on
this?

To verify I can get to our web site, I'm using the
InternetCheckConnection and I find it always reports system error 2250
"This network does not exist" unless I add the parameter
FLAG_ICC_FORCE_CONNECTION which I have found from a post has a value of
1. I have searched all of delphi and find no reference to that
constant. If I use the value 1 as the parameter in the
InternetCheckConnection it returns true. Is this just a stupid omission
from delphi and for that matter, why would I have to say to force the
connection for it to be able to ping the web site? Microsoft does not
mention requiring this parameter for the function to work but it
certainly does not work without it.

Actually I just tried it again with a zero and apparently, once it gets
a successful hit, the next time it returns true even with the zero. But
if I change the name to a bad site name, it again returns the 2250 and
will not connect again until I set the parameter to 1 again. It seems
like windows is maintaining a connection to the site once it pings it.

Is anybody really doing this? Or is there some other way to deal with
it? Like using Indy or one of the alternatives.

Remy Lebeau (TeamB)

unread,
Jan 29, 2008, 1:21:19 PM1/29/08
to

"Joe H" <joed...@att.net> wrote in message
news:479f...@newsgroups.borland.com...

> I've seen a number of posts that claim it is not reliable because if the
> Internet is turned off it will supposedly still show it as available.

It can, yes.

> Anyway I would hope that four years later that things have improved
> on this?

Nope.

> To verify I can get to our web site

Don't even bother trying to detect whether the connection is available.
Just try to connect. It will either succeed or fail on its own.

> I'm using the InternetCheckConnection and I find it always reports system
> error 2250 "This network does not exist" unless I add the parameter
> FLAG_ICC_FORCE_CONNECTION which I have found from a post
> has a value of 1. I have searched all of delphi and find no reference to
> that
> constant.

You are looking in the wrong place. WinInet is a Microsoft technology, not
a Borland/Codegear technology. You need to read Microsoft's documentation:

InternetCheckConnection Function
http://msdn2.microsoft.com/en-us/library/aa384346.aspx

> If I use the value 1 as the parameter in the InternetCheckConnection it
> returns true. Is this just a stupid omission from delphi and for that
> matter,
> why would I have to say to force the connection for it to be able to ping
> the web site?

The only way to reliably test a website is to actually try to download
something from it. So InternetCheckConnection() won't really help you
anyway.

> Actually I just tried it again with a zero and apparently, once it gets
> a successful hit, the next time it returns true even with the zero.

It is likely pulling the file from IE's local cache on subsequent calls.

> But if I change the name to a bad site name, it again returns the 2250
> and will not connect again until I set the parameter to 1 again. It seems
> like windows is maintaining a connection to the site once it pings it.

Not a connection, no. But the actual file, likely.


Gambit


Joe H

unread,
Jan 29, 2008, 12:57:15 PM1/29/08
to
Remy Lebeau (TeamB) wrote:
> > Anyway I would hope that four years later that things have improved
> > on this?
>
> Nope.
>

That's sad--but not surprising.

> You are looking in the wrong place. WinInet is a Microsoft
> technology, not a Borland/Codegear technology. You need to read
> Microsoft's documentation:
>
> InternetCheckConnection Function
> http://msdn2.microsoft.com/en-us/library/aa384346.aspx
>

True but Codegear provides the Interface to it just like the rest of
windows. I had seen this reference you gave before I posted. It's
identical to what's in the help and really doesn't say a damned thing
that might be particularly informative about it -- and it certainly
doesn't reveal that it is worthless. Since I'm using delphi, not vs, I
was hoping other delphi developers would have alternative ways to
accomplish this.

I guess I'll just execute the thread, try to download the file(s)
without checking first to see if Internet is available and maybe set a
timer so that it doesn't just hang. I'm doing this to download a small
compressed file that will tell me if a new version is available and
also some information that I want to auto update. If a new version is
available, I'll ask the user if they want to get and install it and
then download the upgrader in the background and send a message back to
the main thread when it's ready to install.

Thanks for your reply, Remy.

Martin James

unread,
Feb 2, 2008, 3:24:40 AM2/2/08
to

> True but Codegear provides the Interface to it just like the rest of
> windows. I had seen this reference you gave before I posted. It's
> identical to what's in the help and really doesn't say a damned thing
> that might be particularly informative about it -- and it certainly
> doesn't reveal that it is worthless. Since I'm using delphi, not vs, I
> was hoping other delphi developers would have alternative ways to
> accomplish this.

The problem is that 'The Internet' does not exist as a discrete entity and
you cannot determine connection to something that does not exist. 'The
internet' is a world-wide collection of nodes and subnets that is
continually reconfiguring itself. It is not static and its topology,
connectivity, links, routes and the reachability of nodes is dynamic.

If you network cable is unplugged, are you connected to the internet?

If your cable is in, but your local router is powered off, are you
connected?

If your router is on, but your ISP server is down, are you connected?

If your router is on, your ISP server up but the ISP backbone router is
down, are you connected?

If your ISP router is up, but the fibre cable connecting your country to the
country of your target server is broken, are you connected?

If your connectivity to the target country is up, but the ISP router
handling the web server you are trying to reach is down, are you connected?

> I guess I'll just execute the thread, try to download the file(s)
> without checking first to see if Internet is available and maybe set a
> timer so that it doesn't just hang.

If you've threaded off the 'new version' check, then what is the problem?

Rgds,
martin


mayur...@gmail.com

unread,
Dec 7, 2015, 9:01:09 AM12/7/15
to
вторник, 29 января 2008 г., 19:34:20 UTC+3 пользователь Joe H написал:
That's cool.
But How Can I distinguish situations when my server down and when there is no Intenet at all at the client side? Because when my program can't connect my clients begin to call me even when they'd lost Internet connection.
0 new messages