Check Internet Connection

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Muskelkatermann
Earned some good credits
Earned some good credits
Posts: 135
Joined: Thu Apr 28, 2005 11:36 am
Location: Gie

Check Internet Connection

Post by Muskelkatermann » Tue Nov 29, 2005 4:35 pm

Hi,

I'm thinking about how to check whether a client machine is online or not.

I thought of download a specific File from a server and if the returned code is OK, then the machine must be online.

But I guess there is a better way!
How would you solve the Problem?



Greetings

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Re: Check Internet Connection

Post by Ryan Norton » Tue Nov 29, 2005 4:50 pm

Muskelkatermann wrote: But I guess there is a better way!
How would you solve the Problem?



Greetings
Possibly

Code: Select all

wxDialUpManager::IsOnline
[Mostly retired moderator, still check in to clean up some stuff]

emarti
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:

Post by emarti » Tue Nov 29, 2005 11:02 pm

Please, browse "wx\samples\dialup" sample.
- T U R K E Y ?
- I love this country!

WebSites:
http://mebt.sourceforge.net/
http://wxquran.sourceforge.net/

Muskelkatermann
Earned some good credits
Earned some good credits
Posts: 135
Joined: Thu Apr 28, 2005 11:36 am
Location: Gie

Post by Muskelkatermann » Wed Nov 30, 2005 8:39 am

I think this work's only for dialup connections, not?

What about permanent connection with a DSL Router, or Proxy?

greetings

emarti
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:

Post by emarti » Wed Nov 30, 2005 11:35 pm

Not only dialup connection. it works for DSL.
- T U R K E Y ?
- I love this country!

WebSites:
http://mebt.sourceforge.net/
http://wxquran.sourceforge.net/

Muskelkatermann
Earned some good credits
Earned some good credits
Posts: 135
Joined: Thu Apr 28, 2005 11:36 am
Location: Gie

Post by Muskelkatermann » Mon Jan 09, 2006 11:25 am

Hi,

I just tested the wxDialUpManager::IsOnline but this isn't what i want...

It just checks whether all my eth() devices are connected, example:

Eth(0) Cable is unplugges
Eth(1) is removed (pcmcia)
Eth(2) (IEEE 1394) cable is unplugged

wxDialUpManager::IsOnline returns true until i deactivate even the Eth(2).

Any other ideas for an internet connection test ?

greetings

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Mon Jan 09, 2006 12:33 pm

I think it is very hard. Even Firefox tries and tries to connect, even when my connection is down. So, what is the gain in doing so. When you're not able to connect to the other side, either the other PC is dead or your internet connection is.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Muskelkatermann
Earned some good credits
Earned some good credits
Posts: 135
Joined: Thu Apr 28, 2005 11:36 am
Location: Gie

Post by Muskelkatermann » Mon Jan 09, 2006 1:01 pm

Ok,

currently i check for the connection by getting the input stream of a file which is located on the server.

In General that works fine, but today i had the following situation:

I wanted to download a file which is generated by a serversided script(ColdFusion) but something was wrong with the server, and it took up to two minutes until GetInputStream returned data...

I don't like it when the user just has to wait 2 Minutes to get the Message, that he isn't connected.

But I guess I have to live with that so far...


greetings

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Mon Jan 09, 2006 1:18 pm

What I always do is provide a cancel possibility. I do my network I/O in a thread and when the user presses CANCEL in the GUI I provide SetCancel() to the thread that cancels. Ofcourse the thread needs to have no blocking I/O or else you can wait for a long time.
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

jsheets
Earned a small fee
Earned a small fee
Posts: 22
Joined: Wed Oct 19, 2005 1:21 pm

Post by jsheets » Wed Jan 11, 2006 10:48 pm

Part of the problem is it is difficult to tell if you really are connected, DNS can be cached on the local machine or local DNS servers, you can be connected to a LAN and able to access local resources and the main connection can still be down.

Even if the connection is up on a local machine it is possible the Internet host used in verification will be down, which could generate a false "not connected" response.

You can try:

#1 Opening a TCP/IP socket to a service that should be available if you are connected. If the connection times out before it succeeds you can assume either the host is down or for some reason you can't connect, possibly because you aren't connected to the Internet.

#2 Similar to above you can ping a host that either needs to be available for your application to work or one you believe will always be available.

Obviously if the server you are connecting to is unavailable it could tell you it couldn't connect. This isn't as big of an issue if the server connect to is the same server you want to connect to if you are online.

Any of these solutions have the potential to irritate the sever administrator if you aren't building a client / server solution and just want to know if your user is connected to the Internet.

You might also consider shorter timeouts.

Post Reply