473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Determining if a client PC has an Internet connection

Hi,

I'm writing an application that needs to know if an Internet connection
is available. Basically, I want to have something similar to what a lot
of email clients have, where the app can work either in "online" or
"offline" mode (it keeps a cache of downloaded info, so it can work
without a connection if needed).

The basic problem is this: it downloads info (RSS feeds) from a variety
of sources. Any one (or more) of these could conceivably fail to
download, so simply waiting for a timeout isn't sufficient (not easy to
differentiate between having a bad server and the client not having a
connection). Further, if it waits (say 30s) for the timeout to occur,
this is going to be a bit annoying to the user.

I've considered trying to connect to a stable host (i.e. Google) and if
that fails then assume the client can't connect to the internet, but
this seems like a sub-optimal solution.

Is there any way to reliably determine the state of the client's
internet connectivity?

Regards,
Cliff

--
Cliff Wells <cl************@comcast.net>

Jul 18 '05 #1
12 3588
Cliff Wells <cl************@comcast.net> pisze:
I'm writing an application that needs to know if an Internet connection
is available. Basically, I want to have something similar to what a lot
of email clients have, where the app can work either in "online" or
"offline" mode (it keeps a cache of downloaded info, so it can work
without a connection if needed).

The basic problem is this: it downloads info (RSS feeds) from a variety
of sources. Any one (or more) of these could conceivably fail to
download, so simply waiting for a timeout isn't sufficient (not easy to
differentiate between having a bad server and the client not having a
connection). Further, if it waits (say 30s) for the timeout to occur,
this is going to be a bit annoying to the user.

I've considered trying to connect to a stable host (i.e. Google) and if
that fails then assume the client can't connect to the internet, but
this seems like a sub-optimal solution.

Is there any way to reliably determine the state of the client's
internet connectivity?


No, there's no such way. You can try to connect to some "usually
working & available" host, but there always may be some periods, when
this host is not available (scheduled downtime, power outage, you name
it). The hosts known for its greatest stability are root DNS servers.

--
Jarek Zgoda
http://jpa.berlios.de/
Jul 18 '05 #2
* Jarek Zgoda (2004-09-19 10:14 +0200)
Cliff Wells <cl************@comcast.net> pisze:
I'm writing an application that needs to know if an Internet connection
is available. Basically, I want to have something similar to what a lot
of email clients have, where the app can work either in "online" or
"offline" mode (it keeps a cache of downloaded info, so it can work
without a connection if needed).

The basic problem is this: it downloads info (RSS feeds) from a variety
of sources. Any one (or more) of these could conceivably fail to
download, so simply waiting for a timeout isn't sufficient (not easy to
differentiate between having a bad server and the client not having a
connection). Further, if it waits (say 30s) for the timeout to occur,
this is going to be a bit annoying to the user.

I've considered trying to connect to a stable host (i.e. Google) and if
that fails then assume the client can't connect to the internet, but
this seems like a sub-optimal solution.

Is there any way to reliably determine the state of the client's
internet connectivity?


No, there's no such way.


I think there has to be (or at least there is a method that many
coders use because "testing if you're online" is a very frequent
problem).

Thorsten
Jul 18 '05 #3
Thorsten Kampe <th******@thorstenkampe.de> pisze:
Is there any way to reliably determine the state of the client's
internet connectivity?


No, there's no such way.


I think there has to be (or at least there is a method that many
coders use because "testing if you're online" is a very frequent
problem).


There has to be, but isn't. I often see this question on many forums
with single answer. Let me cite ICS FAQ:

"""
There is no perfect solution. Why? Because the Internet is just another
network. Your computer does not distinguish between LAN and Internet.
They are both networks. One of them just happens to be very big.

The Internet is no different to your local network. It is just a matter
of size.

Think about your question. "Am I connected to the Internet?". Try
rephrasing your question to what you really want to ask. "Can I connect
to a specific remote host?" With the question worded like this, you can
start to tackle the problem. How do you find out if you can connect to
the remote host? Try to connect. Simple as that. If the connection
attempt fails, there is no path between you and the remote host or the
remote host is refusing connections.

But, I hear you cry, I do not want the auto-dial the pop up. How do we
get around this? Ask the user how to make a connection. We see this all
the time in other Internet applications. Outlook Express, WinAmp, etc.
They ask the user what sort of network connection they have. From this
information, the applications can make the best choice about how to
connect to a remote host.

There is no proof way. However some things can help.

There is an InternetGetConnectedState function in the WinINet.DLL that
returns true if it detects a connection to the internet. However, the
only thing you can be sure about when using this funtion is that the
computer will not start dialing and not pop up any dialog box when the
function returned true and you afterwards try to do anything on the
internet. In some cases the function may return false although the
computer is connected.
"""

Although it is Win32-only.

--
Jarek Zgoda
http://jpa.berlios.de/
Jul 18 '05 #4
Cliff Wells wrote:
Hi,

I'm writing an application that needs to know if an Internet connection
is available. Basically, I want to have something similar to what a lot
of email clients have, where the app can work either in "online" or
"offline" mode (it keeps a cache of downloaded info, so it can work
without a connection if needed).

The basic problem is this: it downloads info (RSS feeds) from a variety
of sources. Any one (or more) of these could conceivably fail to
download, so simply waiting for a timeout isn't sufficient (not easy to
differentiate between having a bad server and the client not having a
connection). Further, if it waits (say 30s) for the timeout to occur,
this is going to be a bit annoying to the user.

I've considered trying to connect to a stable host (i.e. Google) and if
that fails then assume the client can't connect to the internet, but
this seems like a sub-optimal solution.

Is there any way to reliably determine the state of the client's
internet connectivity?

Regards,
Cliff


As others have mentioned, there's no clean-cut paradigm in the language
that can distinguish between the Internet and your local LAN. Your best
bet is to simple go about your business can try accessing hosts like
normal. When several of your requests timeout, then you can safely
assume the local host to be offline. That's what you see in those
applications when they say you're "offline"; an educated guess. After
all, if you can't reach your target, then you are, for all intents and
purposes, offline.
Jul 18 '05 #5
On Sun, 2004-09-19 at 09:03 +0000, Chris S. wrote:

As others have mentioned, there's no clean-cut paradigm in the language
that can distinguish between the Internet and your local LAN. Your best
bet is to simple go about your business can try accessing hosts like
normal. When several of your requests timeout, then you can safely
assume the local host to be offline. That's what you see in those
applications when they say you're "offline"; an educated guess. After
all, if you can't reach your target, then you are, for all intents and
purposes, offline.


Okay, at this point I suppose the better question would be how to make
an "educated guess". As I mentioned, I've considered trying to open a
socket to one or more relatively stable hosts (i.e. Google, Yahoo, etc)
and if this fails, assume there is no Internet link. However, this
clearly has it's flaws (those services, as unlikely as it seems, could
potentially be down, or they might be blocked by a corporate firewall,
etc). Further, tying the application to an outside source that is, for
all intents, unrelated to the app seems a bit flaky.

Anyway, it occurs to me that a better "guess" might consist of whether
or not the app can reach the PC's primary/secondary DNS servers. If
these are unreachable then it's a fair assumption that we aren't going
to get anywhere anyhow.

So... is there a way of determining the DNS search path of a PC?

Regards,
Cliff

--
Cliff Wells <cl************@comcast.net>

Jul 18 '05 #6
Hi !

Not only Internet, but with good suspicion : test if IP-passerelle is
present and answer to ping.

Then Ping one or two IP "externals and stables".


Jul 18 '05 #7
On Sun, 2004-09-19 at 13:31 +0200, Michel Claveau - abstraction méta-
galactique non triviale en fuite perpétuelle. wrote:
Hi !

Not only Internet, but with good suspicion : test if IP-passerelle is
present and answer to ping.
Sorry, you lost me here: passerelle == bridge?
Then Ping one or two IP "externals and stables".


Again, I don't follow.

Regards,
Cliff

--
Cliff Wells <cl************@comcast.net>

Jul 18 '05 #8
Cliff Wells wrote:
I'm writing an application that needs to know if an Internet connection
is available. Basically, I want to have something similar to what a lot
of email clients have, where the app can work either in "online" or
"offline" mode (it keeps a cache of downloaded info, so it can work
without a connection if needed).
I do not see why there would have to be specific online and offline
modes. They are annoying. Especially when they educatedly guess they are
not on the Internet and refuse to believe the user who says they are.
The basic problem is this: it downloads info (RSS feeds) from a variety
of sources. Any one (or more) of these could conceivably fail to
download, so simply waiting for a timeout isn't sufficient (not easy to
differentiate between having a bad server and the client not having a
connection). Further, if it waits (say 30s) for the timeout to occur,
this is going to be a bit annoying to the user.


So why not assume you are always connected to the Internet. Download
updated info into local cache whenever possible and always show local
cached information. Of course you could somehow indicate the age of the
cached information, so the user doesn't think that local cached
information is up-to-date when it actually isn't.
Jul 18 '05 #9
In article <ma**************************************@python.o rg>,
Cliff Wells <cl************@comcast.net> wrote:
On Sun, 2004-09-19 at 09:03 +0000, Chris S. wrote:

Jul 18 '05 #10
On Sun, 2004-09-19 at 23:54 +0300, Tuure Laurinolli wrote:
Cliff Wells wrote:
I'm writing an application that needs to know if an Internet connection
is available. Basically, I want to have something similar to what a lot
of email clients have, where the app can work either in "online" or
"offline" mode (it keeps a cache of downloaded info, so it can work
without a connection if needed).


I do not see why there would have to be specific online and offline
modes. They are annoying. Especially when they educatedly guess they are
not on the Internet and refuse to believe the user who says they are.


It doesn't refuse. If you tell it that it's online it will faithfully
try to download whether it thinks it is or not. You are making as many
assumptions as you claim my software will ;)
The basic problem is this: it downloads info (RSS feeds) from a variety
of sources. Any one (or more) of these could conceivably fail to
download, so simply waiting for a timeout isn't sufficient (not easy to
differentiate between having a bad server and the client not having a
connection). Further, if it waits (say 30s) for the timeout to occur,
this is going to be a bit annoying to the user.


So why not assume you are always connected to the Internet. Download
updated info into local cache whenever possible and always show local
cached information. Of course you could somehow indicate the age of the
cached information, so the user doesn't think that local cached
information is up-to-date when it actually isn't.


Because it's a customer requirement. Besides, as I outlined in a
separate post, there are actually a couple of good reasons for the app
to know when it's offline:

'''
More importantly, if the app is "online", timing out is returned as an
error to the user, whereas in the "offline" state, as long as the data
is cached, there is no error. Also, in the case of being offline and
there is no data in the cache, the error message is to be different than
if the app is online and the connection fails.
'''

Regards,
Cliff

--
Cliff Wells <cl************@comcast.net>

Jul 18 '05 #11
Cliff Wells wrote:
On Sun, 2004-09-19 at 09:03 +0000, Chris S. wrote:

As others have mentioned, there's no clean-cut paradigm in the language
that can distinguish between the Internet and your local LAN. Your best
bet is to simple go about your business can try accessing hosts like
normal. When several of your requests timeout, then you can safely
assume the local host to be offline. That's what you see in those
applications when they say you're "offline"; an educated guess. After
all, if you can't reach your target, then you are, for all intents and
purposes, offline.

Okay, at this point I suppose the better question would be how to make
an "educated guess". As I mentioned, I've considered trying to open a
socket to one or more relatively stable hosts (i.e. Google, Yahoo, etc)
and if this fails, assume there is no Internet link. However, this
clearly has it's flaws (those services, as unlikely as it seems, could
potentially be down, or they might be blocked by a corporate firewall,
etc). Further, tying the application to an outside source that is, for
all intents, unrelated to the app seems a bit flaky.

Anyway, it occurs to me that a better "guess" might consist of whether
or not the app can reach the PC's primary/secondary DNS servers. If
these are unreachable then it's a fair assumption that we aren't going
to get anywhere anyhow.

So... is there a way of determining the DNS search path of a PC?


My solution was far more mundane. I meant simply try and access the
internet the way you normally would. If it's a mail client, try and
access your users POP server. If it's a web-browser, try and retrieve a
web page the user wants. If you can't access them, then there's
essentially no "internet connection". In other words, don't worry about
whether or not there's an available connection. Instead, assume there is
a connection and worry about the status of your requests on the network.
Jul 18 '05 #12
On Sun, 2004-09-19 at 23:38 +0000, Chris S. wrote:
Cliff Wells wrote:

Okay, at this point I suppose the better question would be how to make
an "educated guess". As I mentioned, I've considered trying to open a
socket to one or more relatively stable hosts (i.e. Google, Yahoo, etc)
and if this fails, assume there is no Internet link. However, this
clearly has it's flaws (those services, as unlikely as it seems, could
potentially be down, or they might be blocked by a corporate firewall,
etc). Further, tying the application to an outside source that is, for
all intents, unrelated to the app seems a bit flaky.
>
Anyway, it occurs to me that a better "guess" might consist of whether
or not the app can reach the PC's primary/secondary DNS servers. If
these are unreachable then it's a fair assumption that we aren't going
to get anywhere anyhow.

So... is there a way of determining the DNS search path of a PC?


My solution was far more mundane. I meant simply try and access the
internet the way you normally would. If it's a mail client, try and
access your users POP server. If it's a web-browser, try and retrieve a
web page the user wants. If you can't access them, then there's
essentially no "internet connection". In other words, don't worry about
whether or not there's an available connection. Instead, assume there is
a connection and worry about the status of your requests on the network.


Well, this is the fundamental problem. It's an RSS aggregator, so there
is no single server it will be connecting to. Further, because servers
can be added by the user or simply "disappear" because some blogger
decides he doesn't want to maintain a feed anymore, getting connection
errors will probably be quite common.

Additionally, because I'm using Twisted, fetching the sites is
asynchronous, so I'm updating the cache and determining error messages
long before I have a chance to determine that all of the connections are
failing. By the time I have that information, the damage has been done,
so to speak.

Given this situation, and the fact that there are specific requirements
(mentioned elsewhere) leaves me little choice but to use some guesswork
to determine whether or not a connection is present *prior* to fetching
feeds.

Anyway, at this point I'm using the rather lame "check if both google
and yahoo are unavailable" method. I'll find something better when I
have more time to devote to it. I may use the effbot's suggestion for
Windows (InternetCheckConnection) and some other method for Linux and
OS/X.

Regards,
Cliff

--
Cliff Wells <cl************@comcast.net>

Jul 18 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Richard Choate | last post by:
I'm writing an article and I need your informed opinions, so I ask you this: 1. Doesn't the web-enabled app generally run slower for one reason or another? 2. Isn't the fact that application...
6
by: Paul | last post by:
Hi, Is their a client side VBscript command that I can use to post the local IP address of the machine back to my web server. I want to obtain the client's side IP address of their machine....
88
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
3
by: D. Yates | last post by:
Hi, I'm about to embark on a project that will both send and receive information to/from our client computers in the field. The area that I still need to finalize is the method of...
1
by: hendyhanusin | last post by:
Dear all, 1. Currently, i have a database windows application and it's attached to a card reader device on client computer... in intranet (TCP/IP network), it's easy to maintain this client...
4
by: David C. Barber | last post by:
my.computer.printers.defaultprinter doesn't exist in 2005, despite the plethora of examples still out on the web detailing its use. So how can I determine a person's default printer using ASP 2?...
0
tjc0ol
by: tjc0ol | last post by:
Hi guys, I'm a newbie of this stuffs, We had a small office network (1 Windows 2K - Server) and (3 Windows XP - Client). I am testing to 1 PC (Windows 2K) installed with Licensed Wingate...
22
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
3
by: dynamo08 | last post by:
Hi, I am new to socket programming, I wrote an ftpclient which connects to an ftp server and downloads a file to the client computer. Now in one client connection I want to download multiple files...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.