I am implementing an auto update feature in a program I am writing. It will
optionally check for a new version when the program is launched. I would like this to be as seamless as possible. I am currently using WinInetLibrary<<ping: to test for a connection. I am also considering wrapping and using the InternetGetConnectedState API function. Though I wonder if this is redundant to what ping checks, if so there is no point. Regardless, the problem I have is that when I disconnect the network cable from a PC (to imitate a network outage) the ping is quite slow to fail thereby slowing the application load time. I suppose that is due to some sort of timeout. Does anyone know of a robust way to reliably check for an Internet connection passively? I suspect that fork would not work given that it is an API call. I would also like to do this the simplest way possible. Any ideas? Chris |
Hi Chris,
Christopher J. Demers wrote: > I am implementing an auto update feature in a program I am writing. > It will optionally check for a new version when the program is > launched. I would like this to be as seamless as possible. I am > currently using WinInetLibrary<<ping: to test for a connection. I am > also considering wrapping and using the InternetGetConnectedState API > function. Though I wonder if this is redundant to what ping checks, > if so there is no point. Regardless, the problem I have is that when > I disconnect the network cable from a PC (to imitate a network > outage) the ping is quite slow to fail thereby slowing the > application load time. I suppose that is due to some sort of timeout. > > Does anyone know of a robust way to reliably check for an Internet > connection passively? I suspect that fork would not work given that > it is an API call. I would also like to do this the simplest way > possible. > > Any ideas? Hi Chris, I also needed to do this, and found no easy solution. All the reading I did suggested that if you need your application to work across all versions of windows the easiest way is to roll your own. XP (and probably 2000) have some new APIs that could be used, but the wininet functions behave inconsistently across versions and are buggy on certain versions of 98/95. If you are targeting home users, rather than wrapping InternetGetConnectedState I would suggest wrapping InternetAttemptConnect. If the user connects via a network it will always answer true, but if the user connects via dial-up on demand, it will block showing a dialog-box asking the user to make a connection. That does not guarantee that you have a connection (but neither does InternetGetConnectedState and friends in the real world). I have read a number of suggestions that after calling InternetAttemptConnect do an os ping to a number of root servers. However what I have done is to do a number of http HEAD requests to major servers. I set a 15 second time-out and if I get back a response, I consider the user to be connected. It would be easier if you are deploying only to XP and 2000, but I dont recall the details of the new APIs. Hope this helps, Steve -- Steve Waring Email: [hidden email] Journal: http://www.stevewaring.net/blog/home/index.html |
In reply to this post by Christopher J. Demers
Christopher J. Demers wrote:
> I am implementing an auto update feature in a program I am writing. > It will optionally check for a new version when the program is > launched. I'd suggest a different tack. I think it's rude for an application to make an outbound connection without the user's consent (obtained in advance), this is especially true in cases where the user may have a dial-up connection (which seems likely or there wouldn't be an issue at all) since establishing a connection may cost the user money. So, if you have an option to check for updates at user-specified times (which is not on by default, though there's nothing wrong with a first-use prompt to ask what the setting should be), then you can assume that the net connection is available at the appropriate time since the *user* has told you it's OK to make a connection then. Hence it's OK to fail slowly if the connection is not available after-all. Then too, what do you mean by "available" ? I can think of several meanings, and it's not clear which one you should be using to determine whether to do a check. Physically the machine could be connected to the net*, in a position to establish a connection to the net, or be incapable of reaching the net. A different axis of variation is that it could be "working off-line" (in which case the MS wrappers for normal TCP/IP connections will fail, but a direct connection at the sockets level will work) or fully "on-line". A last axis of variation is that it could be in a time or place where creating an outbound connection will irritate the user, or where it would be perfectly welcome. There may be security issues too but, of course, that depends on your application and your users. -- chris [*] and on which network adapter ? My XP laptop can't do it's get-the-time-from-the-Net trick and I think that's because it's trying to talk NTP over the wireless link (which is, of course, not turned on) and somehow manages not even to try routing the packets over my wire LAN (where, as it happens, they would be blocked by my firewall, but *it* doesn't know that...) |
"Chris Uppal" <[hidden email]> wrote in message
news:3f20efda$0$46013$[hidden email]... > Christopher J. Demers wrote: > > > I am implementing an auto update feature in a program I am writing. > > It will optionally check for a new version when the program is > > launched. > > I'd suggest a different tack. > > I think it's rude for an application to make an outbound connection without the > user's consent (obtained in advance), this is especially true in cases where > the user may have a dial-up connection (which seems likely or there wouldn't be > an issue at all) since establishing a connection may cost the user money. I should clarify. I am not trying to passively check for the actual update (unless they are already connected), I just want to passively check for the presence of an existing Internet connection. If they are connected the program will check, if they are not connected I don't want it to prompt them to connect or even try to connect. The program will just skip the check. All of this is an option available upon setup and within the program, defaulting to off. I am just trying to give them the option to check for an update when the program is run, they can also do it manually. I suspect most users will have direct Internet connections, I just don't want the program start up to be slow if it can't connect to the update site due to a network problem. I appreciate your concerns, which is why this is all optional and defaulted to off. I just want to make it work well if the user should decide to turn it on. ;) Chris |
In reply to this post by Steve Alan Waring
"Steve Waring" <[hidden email]> wrote in message
news:bfq8pl$hj7b8$[hidden email]... > Hi Chris, > > Christopher J. Demers wrote: > > Does anyone know of a robust way to reliably check for an Internet > > connection passively? I suspect that fork would not work given that > > it is an API call. I would also like to do this the simplest way > > possible. ... > That does not guarantee that you have a connection (but neither does > InternetGetConnectedState and friends in the real world). I have read a > number of suggestions that after calling InternetAttemptConnect do an os > ping to a number of root servers. However what I have done is to do a number > of http HEAD requests to major servers. I set a 15 second time-out and if I > get back a response, I consider the user to be connected. I think I may do the same. I imagine that I could write my own socket stuff to do a quick check, and fork it so it does not slow down the program load due to the timeout. Thanks, Chris |
Free forum by Nabble | Edit this page |