I'd love to see your code Mathew, sounds interesting ...
Thanks
Printable View
I'd love to see your code Mathew, sounds interesting ...
Thanks
Oops...Sorry for the delay. Yesterday we had an unexpected shutdown :mad: of the gateway at our office. I'm attaching the file LSP.zip. A readme.txt explains the installation steps. I hope I last left the code at a working condition. If there is anything let me know. :)
Oops...again:mad: . Retrying to attach...
i have done what mathew joy suggested......here is the sequence of functions called by ie via lsp
1) wspstartup
2) wspbind
3) wspgetsockname
4) wspconnect
5) wspselect
after this if the pc is not connected to internet then it will always call wspselect and otherwise wspsocket and so on
so i conclude that connect with timeout should be the right approach.........any comments
I think a resonable timeout upper limit is 20 secs. Most of the application, including the connect() api, (although it can be changed) waits for 20 secs. Depending on the application for which we are building, this can be reduced. For a simple normal application I guess some 3-5 secs as time-out would be sufficient.
but when i did this with CAysncsocket the sequence was different. Now the questoin is to recreate the magical sqquence or use the connect with timeout ...........
Hey Jase,
For me InternetGetConnectedStatus worked ok for dialup and LAn settings.
I tried checking it when.
1] Dial up is installed but no connection. (I got INTERNET_RAS_INSTALLED and false in return)
2] Dial up connected. (I got INTERNET_RAS_INSTALLED & INTERNET_MODEM_CONNECTED& INTERNET_MODEM_CONFIGURED) and TRUE in return.
3] LAN but no Internet
I got (INTRENET_RAS_INSTALLED with FALSE return)
4] LAN and internet connected.
I got INTERNET_RAS_INSTALLED & INTERNET_LAN_CONNECTED with TRUE in return.
I tried several other conditions also and found it works ok. I didnt restarted the application and kept checking the diff. conditions by uninstalling TCP/IP , disabling LAN , disabling dial up default etc.
I tried this code on Win2k , I dont know how it works on 98 , and I guess it will work ok on XP.
What do you guys say , when did it actully failed for you ?
But I believe you that this way isnt reliable, MSDN says same. Thats why i am also interested in finding a perfect way.
I saw that Internet explorer also fools down in concluding the connection some times, like I saw if you disable the LAN and connect using dialup , and disconnect the dialup connection and reenable LAN , IE asks to go ONLINE showing dialup entries to use.
Have u observed it ? I think IE also dont have perfect way.
can u send me that part of the code i can also down here
Get it here..
Hi Krishnaa ...Quote:
Originally posted by Krishnaa
I tried several other conditions also and found it works ok. I didnt restarted the application and kept checking the diff. conditions by uninstalling TCP/IP , disabling LAN , disabling dial up default etc.
I tried this code on Win2k , I dont know how it works on 98 , and I guess it will work ok on XP.
What do you guys say , when did it actully failed for you ?
Thanks for your post. I checked your code and it failed immediately :)
I have an external Motorola DSL modem - connected via standard network cable to a Netgear hardware router. The router has another network cable connecting it to my PC's 10/100 NIC.
Effectively, the router is a hardware firewall which shares the dsl modem among pc's on my network.
I run your program and click on the button - "Connected", it correctly reports.
I then turn off my modem - no internet connection is now possible. I click the button "Connected".
I turn back on the modem and turn off the router - no internet connection is possible. I click the button "Connected".
I unplug my pc from the LAN by pulling the cable out of my NIC. My pc is now totally standalone with no external connections to network , internet or other. I click the button "Connected" it tells me.
Perhaps it works with dialup - but as technology becomes more readily available and cheaper, less and less people will be using 56k modems - moving across to broadband internet instead.
InternetGetConnectedState() simply does not work.
You have to use winsock APIs rather than CSockets. For such situations you need to have more control over what is happening...so APIs are the best.Quote:
Originally posted by anima_sg
but when i did this with CAysncsocket the sequence was different. Now the questoin is to recreate the magical sqquence or use the connect with timeout ...........
I think what Jase should do is to choose one of the method that suits the situation. The user should have the responsibility to fix the problem. Well, to know if there is net connection we all use IE to check. So I think we should follow the approach that IE uses. Searching for the 'fool proof' solution if one doesn't exist is just a waste of time. In the course of time, if someone gets such a solution, please participate us with it.Quote:
Originally posted by jase jennings
Thanks for your post. I checked your code and it failed immediately
The IE way isn't foolproof either. I'm running my internet off a DSL/LAN.
When I installed WinXP, and started IE, it always popped up a dial-up networking (DUN) connection dialog, which I don't need for internet, but need for connection to client VPN's. Clearly this DUN wasn't needed, since internet is always up (except when I turn the modem off).
It took me some time to figure out how to make IE no longer popup the DUN, but still make DUN work for the VPN's.
I'm not the expert on internet related stuff, but I think it's a bit of a catch 22.
The only way to detect if you REALLY have internet, is to actually open the connection you need to the remote server. Without that, whatever method you try for attempting the connection may get blocked by HTTP proxy or router. (note that ICMP packets are more and more getting blocked).
And actually opening a connection to a remote server may popup the DUN, you may be able to get around the standard Windows DUN, but not everyone uses that (like me). There are several other connection software packages.
"temporarily" disabling the DUN by changing the registry as someone suggested won't work for anything but MS' default DUN (and it's a bad idea messing with such registry settings from your code anyway).
the IE way may be more or less the safest way, but you should provide a way in your code to override the code (providing a 'detect', 'assume never online' & 'assume always online' kind of approach). I know at least 3 programs I can't use at home because they INSIST on starting DUN, and won't run until DUN made a connection to the internet (which it never does, since internet doesn't go over DUN in my case). Tech support of those programs told me to 'deinstall DUN if you have internet over LAN', but that isn't an option because I need DUN. It's very annoying to have software that's this inflexible. (and tech support which is even more rigid)
i have made a small utility for checking the connection...........
Hey, guess what? ....
Doesn't work!
Tells me i am not connected, although i have a connection via dsl modem. I couyldn't find a way to get this to report "connected" :(
Jase
hey even i have a dsl modem and it is working fine ..............i''ll send the debug version which will report the error so we know why is it happening can u pls test it
here is the debug version
Did anybody try InternetCheckConnection API. Its a straight forward API. And is available with all the OS relevant today.:)
Onkar pls read this post
it returns "error not defined" - "not connected".Quote:
Originally posted by anima_sg
here is the debug version
I'm on windows XP.
Hi anima_sg,
could you send the sources instead of binaries ?
means the error is not defined by the socket.............. i am uploading the code
I get the following error when i compile the testconnection:
tda2Dlg.obj : error LNK2001: unresolved external symbol __imp__InternetGetConnectedState@8
What do i have to do?
You need to add wininet.lib to the link section of the project properties
So, did you find the foolproof version of the internet connection detection?Quote:
Originally posted by jase jennings
You need to add wininet.lib to the link section of the project properties
I think as perfect an answer as you're gonna get lies in the answers above :)
I haven't gotten around to coding it yet due to time demands on another project. When I do, I'll post it. If someone else does it first, I'd really appreciate them sharing it here.
Thanks guys
There are some problems with this program!Quote:
Originally posted by anima_sg
means the error is not defined by the socket.............. i am uploading the code
Under Win98, when the first time the internet connection is tested, the dial-up dialog box pops up!
Under WinXp: if you have more dial-up connections setted up, the 'Network connection' dialog box pops up to select the ISP, to wich you want to connect!!!
Waiting for solutions!
Thanks!
When using wininet functions, the autodialer will be displayed if the user has configured dial-up-networking and is not connected. This is one of the issues of trying to detect a connection invisibly.
You can overcome this though!
The autodialer is configured in the registry, so it can be turned off/on at your will before calling into the wininet functions.
The following code is from my own connection class which I don't want to publish in its entirety because it isn't the greatest code i ever wrote, and it's by no means the complete solution we're all looking for :) Take a look at the registry sections to see that i am turning the autodialer off, then back on (if it was on originally) after checking the connection. I actually give the user a choice in the UI as to whether they want DUN launched if they are not connected - "Initiate a DUN connection when not connected?".
Hopefully the code will illustrate the principal - if not, ask questions and i'll try to break it down.
Code:byte CInternetConnexion::DetectWithAutodial(byte byteAutodial /* = IC_ENABLEAUTODIAL */)
{
LOG("CInternetConnexion::DetectWithAutodial() Enter");
CString s;
HKEY hKey;
DWORD dwDial, dwDialType = REG_DWORD, dwDialSize = 4, dwNew = 0;
byte byteConnected = IC_DISCONNECTED;
if(byteAutodial == IC_DISABLEAUTODIAL)
{
if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKey) != ERROR_SUCCESS)
{
LOG("Cannot open Internet Settings");
LOG("CInternetConnexion::Detect() Exit <false>");
return byteConnected;
}
if(RegQueryValueEx(hKey, "EnableAutodial", NULL, &dwDialType, (BYTE *) &dwDial, &dwDialSize ) == ERROR_SUCCESS )
{
if(RegSetValueEx( hKey, "EnableAutodial", NULL, dwDialType, (BYTE *) &dwNew, dwDialSize ) != ERROR_SUCCESS)
{
LOG("Cannot disable EnableAutodial");
LOG("CInternetConnexion::Detect() Exit <false>");
return byteConnected;
}
}
else
{
LOG("Cannot disable EnableAutodial");
LOG("CInternetConnexion::Detect() Exit <false>");
return byteConnected;
}
}
#ifdef _DEBUG
CTime t;
t = CTime::GetCurrentTime();
s.Format("OpenURL started at %02d.%02d:%02d\n", t.GetHour(), t.GetMinute(), t.GetSecond());
TRACE((LPCTSTR)s);
#endif
// start up a thread to check for a connection
m_tParams.lpURL = (LPCTSTR)m_sUrl;
m_tParams.pByteConnected = &byteConnected;
DWORD dwThreadID;
HANDLE hThread = CreateThread(NULL, NULL, CheckConnection, &m_tParams, 0, &dwThreadID);
// two choices ...
if(byteAutodial == IC_DISABLEAUTODIAL)
{
// there is no possibility of an autodial
// so wait for 5 seconds, or until the thread returns - whichever comes soonest
WaitForSingleObject(hThread, TIMEOUT);
}
else
{
// wait until the thread exits - no timeout used here.
// this is because the user may have launched an autodialer and maybe trying to
// connect to the internet now. It would be a bit rude to just give up ...
// This will timeout eventually, or finish when the user makes the connection.
WaitForSingleObject(hThread, INFINITE);
}
#ifdef _DEBUG
t = CTime::GetCurrentTime();
s.Format("OpenURL finished at %02d.%02d:%02d\n", t.GetHour(), t.GetMinute(), t.GetSecond());
TRACE((LPCTSTR)s);
#endif
if(byteAutodial == IC_DISABLEAUTODIAL)
{
// no need to error check this key, we know it exists now ...
RegSetValueEx( hKey, "EnableAutodial", NULL, dwDialType, (BYTE *) &dwDial, dwDialSize);
RegCloseKey(hKey);
}
#ifdef LOGGING_ON
byteConnected == IC_CONNECTED ? s.Format("Connected to internet") : s.Format("Not connected to internet");
LOG(s);
#endif
LOG("CInternetConnexion::DetectWithAutodial() Exit");
return byteConnected;
}
i am having a shared internet connection on LAN with a local server connected to cable net. i wanted to check internet connection with the remote server before putting a request for a particular page in my partner project. The code given below worked for my purpose,
CInternetSession session;
CStdioFile* myfile;
try
{
myfile=session.OpenURL("http://www.indosoftsys.com");
MessageBox("Internet Connection Exits");
}
catch(CInternetException* ie)
{
char errMsg[80];
ie->GetErrorMessage(errMsg,80);
strcat(errMsg,"Check your internet connection or Server name");
MessageBox(errMsg);
}
Try this. It works with a LAN connection but I can't test with dial up
#include "Iphlpapi.h"
MIB_IPFORWARDROW BestRoute;
DWORD dwResult = GetBestRoute(inet_addr("62.232.0.152"), 0, &BestRoute);
it returns 0 when the NIC is enabled and 1003 when disabled or unplugged.
Try this. It returns 0 when NIC is connected and 1003 when disabled/unplugged.
#include "Iphlpapi.h"
MIB_IPFORWARDROW BestRoute;
DWORD dwResult = GetBestRoute(inet_addr("62.232.0.152"), 0, &BestRoute);
This thread is already 6 pages. I think it would have been better if a new thread in this forum were used to ask this question instead of adding the question to this thread.Quote:
Originally posted by je_e_tu
i am having a shared internet connection on LAN with a local server connected to cable net. i wanted to check internet connection with the remote server before putting a request for a particular page in my partner project. The code given below worked for my purpose,
I think it is entirely pertinent to ask the question here, as it is in context with the rest of thread...Quote:
Originally posted by Sam Hobbs
This thread is already 6 pages. I think it would have been better if a new thread in this forum were used to ask this question instead of adding the question to this thread.
It would be better to discuss this topic and possible solutions within the same context, rather than to fragment it across several posts, making any future miracle cure harder to find.
Hi BobQuote:
Originally posted by Bob Sheep
Try this. It works with a LAN connection but I can't test with dial up
#include "Iphlpapi.h"
MIB_IPFORWARDROW BestRoute;
DWORD dwResult = GetBestRoute(inet_addr("62.232.0.152"), 0, &BestRoute);
it returns 0 when the NIC is enabled and 1003 when disabled or unplugged.
Thanks for your suggestion
I'm sorry to say that it doesn't work ...
I can turn my broadband modem off, ensuring no connection to the inet, yet it will still say that i am connected. Perhaps it provides a good measure of whether i am connected to a network, I haven't tested it from this perspective. However, there is no possible way of reaching the ip address in your code, yet it still returns 0.
I think the problem is the fact that the network card is active and that as far as the computer is concerned indicates it has an internet connection. It does not seem to care that there is nothing further on than this. I get the same result as you when I connect to a hub. The NIC is active and says I'm connected even though the hub goes nowhere. I think you're going to have to use the connect/wait/retry solution as there's no way to detect the presence of valid routes further down the line from the NIC.
Why do people constantly slag each other off on these forums.
Sorry I joined this one.
Bye (forever)
I am not sure Jase but take a look on function InternetGetConnectedState:
http://support.microsoft.com:80/supp...NoWebContent=1
I don't see anybody "slagging" anybody off Bob.Quote:
Originally posted by Bob Sheep
Why do people constantly slag each other off on these forums.
Sorry I joined this one.
Sam is simply putting forward a point of view on how best to organise threads and questions.
I don't happen to agree with him in this case, but I don't see that anybody here has been violated.
Why? You have good information to contribute - and nobody has said anything to offend you. If you don't like a post, the best thing to do is just ignore it - pretend it wasn't posted.Quote:
Bye (forever)
Hi SamQuote:
Originally posted by Sam Hobbs
Is the new question the same question as the original question or is it different (whether related or not)?
The post you have quoted is not a question, it is a suggestion for how to detect an internet connection - which is what this thread asks for.
I agree with you in principal Sam - but in this case your objection does not seem reasonable. Perhaps you quoted the wrong post?
I think you are correct; I made a mistake. I don't know why I thought it was a question.Quote:
Originally posted by jase jennings
The post you have quoted is not a question, it is a suggestion for how to detect an internet connection - which is what this thread asks for.
I agree with you in principal Sam - but in this case your objection does not seem reasonable. Perhaps you quoted the wrong post?
Since this is the first and only post from je_e_tu, I have made a bad impression on je_e_tu. I am sorry. I hope je_e_tu continues to help.
No problem Sam. I also hope he continues to contribute. Same goes for Bob Sheep.Quote:
Originally posted by Sam Hobbs
I think you are correct; I made a mistake. I don't know why I thought it was a question.
Since this is the first and only post from je_e_tu, I have made a bad impression on je_e_tu. I am sorry. I hope je_e_tu continues to help.
Been there, done that :) Doesn't work as described...Quote:
Originally posted by Narva
I am not sure Jase but take a look on function InternetGetConnectedState:
http://support.microsoft.com:80/supp...NoWebContent=1
Greetings Jase!
Been a long time. I have been looking for a solution to the problem this 90+ response thread has generated. I HAVE NEVER FOUND A RESONABLE SOLUTION EITHER. It is extremely frustrating! There is no reasonable way to actually check for connectivity. Don't give up, someday there will be an answer. I hope....
Hi Alan
Nice to hear from you again :)
There IS an answer already. Just open up Internet Explorer - it knows exactly when you are connected and when you are not.
But we don't know it ... or at least not the complete solution anyway.
I keep responding to this post in the hope that somebody will deliver us an API function which we are all missing :)
Here's hoping anyway...
I've had luck using InternetOpen followed by InternetOpenUrl to validate a connection to a specific URL.
why not timeout's
if whe talking about autoupdate
the user may be connected to internet
but autoupdate site still unrechable:)
this is a simple winsock based function
that checks for connectivity based on the validation of the IP address, i.e. if the ip returns x7.0.0.1, you are not connected, very simple, and i have had no troubles with it.
int GetInfo()
{
WSAData wsaData;
WSAStartup(MAKEWORD(1, 1), &wsaData);
bool connected = false;
char thisHost[80];
gethostname(thisHost, sizeof(thisHost));
struct hostent *pHe = gethostbyname(thisHost);
if(strncmp(pHe->h_addr_list[0],"\x7f\x0\x0\0x1", 4)==0)
connected = false;
else
connected = true;
WSACleanup();
}
i've also include a simple app based on this routine.
the app includes borrowed code, namely the CLed class for exhibiting transparent Leds and also a vector template from localipquery or something like that.
in the app, the use of a timer allows for realtime updating of the connectivity status, the hostname, and the IP.
Assuming you've figured out how to detect an Internet connection, THEN WHAT?
I really like the way Microsoft and others provide a menu item, Check for Updates. Often, these connections link to some server that has the capability of investigating your current software capabilities and suggesting updates or not if they are indicated.
Does anyone have a clue as to how this is done? I presume that your resident software sends some version information to the server. The server must then interpret the info sent and respond appropriately, either by:
1 - Do you wish to download and install the updates now?
2 - No updates are required.
3 - No updates are available.
I have a server available to do this sort of thing, but havnt a clue as to how to proceed.
Any thoughts greatly appreciated. Thanks.
Mike
Hi Mike
The server may only provide actual version information. The client receives this information, checks whether an update is possible / recommended and queries the server for the respective updated files. Ater receiving the files, the client process starts the downloaded update or installs the downloaded files.
Hi Jase
As I read in this post, you did various checks with the IE. I'm connected via peer to peer (over a switch) LAN with a gateway computer that provides DSL. Played a little with the IE (v5.00.2614.3500, Win98se) and found the following:
Disconnected the internet at the gateway computer and started IE. Tried to navigate to www.microsoft.com. IE tried some urls (according to the status bar of IE, appended .com/.org etc.) about 20 seconds each. Tried another page and IE tried to connect about 40 seconds, then tried variations.
So I do not understand what exactly IE does that is better than a simple "OpenURL" or "Connect" (except IE obviously do it asynchronous).
BTW, if IE do a better job than we can right now, can't we just use IE (via COM interface) to do our task? Ok, our customers would need a specific minimal version of IE. Just an idea.
Oliver.
Hello MikeQuote:
Originally posted by Mike Pliam
Does anyone have a clue as to how this is done? I presume that your resident software sends some version information to the server...
Mike
The way SlideShow Desktop does this, is really very simple.
I hold a text file on my website, my application can retrieve it using standard microsoft internet api calls,
( I forget which ones ). With this small text file held in memory, I parse the information and react appropriately.
The text file contains the version number of the latest release, the url for the release, and descriptive text regarding the release.
I also place in here the url of the most recent text file containing the update information.
When installing the application, a registry key is created containing the url of the update file.
So when you choose to check for update, it fetches the url held in the registry.
If the url contained in the file is different to the one you have just fetched, it writes the new value to the registry,
and then goes through the process again - allowing it to pick up the new file in the event you
have decided to change its name or location.
The version number in the text file is compared with the version held internally by the app.
If the text file contains a later release, you popup your dialog asking "do you want to update".
If yes, you use the same standard api calls again to download the update (typically, it's an installshield installation set).
When it's downloaded, you can then ask the user if they wish to update.
If they do, you run the installer using ShellExecute, then exit your app.
The implementation is entirely up to you. The point being, all you have to do is retrieve a text file from your website, and you have the basis of your update procedure.
Hope this helps. Feel free to ask questions.
Right, I'm off to take a look at this tcp code that's been posted by jtevermore :)
@jtevermore
Sorry, but I always get blue moving LEDs independend of whether I'm connected or not. (As I wrote in my previous post, I'm connected via peer to peer network (+switch) with a internet gateway computer (DSL)).
Nothing happens when I switch off the internet connection at the gateway :(
BTW, I've assigned a static IP, maybe that's the cause?
Oliver.