User Tools

Site Tools


getting_20connected_20and_20online

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
getting_20connected_20and_20online [2018/03/31 13:19] – external edit 127.0.0.1getting_20connected_20and_20online [2024/01/05 00:22] (current) – external edit 127.0.0.1
Line 2: Line 2:
  
 //by Malcolm Marten, August 2007//\\ \\  The simple method of downloading a web page [[/Downloading%20a%20file%20from%20a%20URL|"Downloading a file from a URL"]] can fail if you are not connected or not online.\\ \\  While this sounds obvious, the nature of the Internet being a connected web makes this a little more complicated than you might think. The Windows environment has the concept of "Working Offline" so that previously downloaded content can be used locally. In "Offline" mode a connection can be "made" but it is only to your local machine, or perhaps the local network but not the actual Internet. So calls that you think are opening a network connection are in fact just accessing your local machine, and give 'success' results. Calls such as "URLDownloadToFileA" can subsequently fail although the connection is working correctly.\\ \\  We need two API calls to clear up the situation and inform the user accordingly. The first is "InternetGetConnectedState", a most useful call that returns a TRUE if Windows thinks that there is a valid Internet connection route available. It does not actually try the connection so it is saying that it should work. If it returns FALSE then there is no discernible connection route.\\ \\  The important information about whether you are Offline is returned in a bit set in the returned status flag that also gives other information. The flag can have a combination of the following bits set.\\ \\  &40 INTERNET_CONNECTION_CONFIGURED\\  Local system has a valid connection to the Internet, but it may or may not be currently connected.\\ \\  &02 INTERNET_CONNECTION_LAN\\  Local system uses a local area network to connect to the Internet.\\ \\  &01 INTERNET_CONNECTION_MODEM\\  Local system uses a modem to connect to the Internet.\\ \\  &20 INTERNET_CONNECTION_OFFLINE\\  Local system is in offline mode.\\ \\  &04 INTERNET_CONNECTION_PROXY\\  Local system uses a proxy server to connect to the Internet.\\ \\  To get any new information from the Internet you must be online and connected. We can force the state to Online by using the second API call "InternetGoOnline". This will switch to Online mode, prompting the user if not already Online, and automatically call up the Dial Up Network if necessary to connect.\\ \\  Here is a modified version from [[/Downloading%20a%20file%20from%20a%20URL|"Downloading a file from a URL"]] to show how this is all put together.\\  Set Verbose% to FALSE if you do not want status reporting.\\ \\  //by Malcolm Marten, August 2007//\\ \\  The simple method of downloading a web page [[/Downloading%20a%20file%20from%20a%20URL|"Downloading a file from a URL"]] can fail if you are not connected or not online.\\ \\  While this sounds obvious, the nature of the Internet being a connected web makes this a little more complicated than you might think. The Windows environment has the concept of "Working Offline" so that previously downloaded content can be used locally. In "Offline" mode a connection can be "made" but it is only to your local machine, or perhaps the local network but not the actual Internet. So calls that you think are opening a network connection are in fact just accessing your local machine, and give 'success' results. Calls such as "URLDownloadToFileA" can subsequently fail although the connection is working correctly.\\ \\  We need two API calls to clear up the situation and inform the user accordingly. The first is "InternetGetConnectedState", a most useful call that returns a TRUE if Windows thinks that there is a valid Internet connection route available. It does not actually try the connection so it is saying that it should work. If it returns FALSE then there is no discernible connection route.\\ \\  The important information about whether you are Offline is returned in a bit set in the returned status flag that also gives other information. The flag can have a combination of the following bits set.\\ \\  &40 INTERNET_CONNECTION_CONFIGURED\\  Local system has a valid connection to the Internet, but it may or may not be currently connected.\\ \\  &02 INTERNET_CONNECTION_LAN\\  Local system uses a local area network to connect to the Internet.\\ \\  &01 INTERNET_CONNECTION_MODEM\\  Local system uses a modem to connect to the Internet.\\ \\  &20 INTERNET_CONNECTION_OFFLINE\\  Local system is in offline mode.\\ \\  &04 INTERNET_CONNECTION_PROXY\\  Local system uses a proxy server to connect to the Internet.\\ \\  To get any new information from the Internet you must be online and connected. We can force the state to Online by using the second API call "InternetGoOnline". This will switch to Online mode, prompting the user if not already Online, and automatically call up the Dial Up Network if necessary to connect.\\ \\  Here is a modified version from [[/Downloading%20a%20file%20from%20a%20URL|"Downloading a file from a URL"]] to show how this is all put together.\\  Set Verbose% to FALSE if you do not want status reporting.\\ \\ 
 +<code bb4w>
         url$ = "http://www.bbcbasic.co.uk/bbcwin/bbcwin.html"         url$ = "http://www.bbcbasic.co.uk/bbcwin/bbcwin.html"
         file$ = "C:\bbcwin.html"         file$ = "C:\bbcwin.html"
Line 27: Line 28:
         IF res% ERROR 100, "Couldn't download "+url$ ELSE IF Verbose% PRINT "File downloaded to "+file$         IF res% ERROR 100, "Couldn't download "+url$ ELSE IF Verbose% PRINT "File downloaded to "+file$
         ENDPROC         ENDPROC
-   +</code>   
getting_20connected_20and_20online.1522502362.txt.gz · Last modified: 2024/01/05 00:17 (external edit)