Check for an Internet Connection – Part Two of Three
This is Part Two of this article series. Read Part 1 here
What we learned in the first article of this series was that the best applications have the best validation and the least occurrences of errors. We learned that we are able to import external libraries with ease and that we can utilize these libraries for various methods. The method we are dealing with in this example is the InternetGetConnectedState.
I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.
static extern bool InternetGetConnectedState(ref StateOfConnection lpdwFlags, int dwReserved);
In this article we will explain the definitions of the various connection states and start to build our application.
Definition of Connection States Fig. 1
- Local system has a valid connection to the Internet, but it might or might not be currently connected.
- Local system uses a local area network to connect to the Internet.
- Local system uses a modem to connect to the Internet.
- Modem Busy:
- No longer used.
- Local system is in offline mode.
- Local system uses a proxy server to connect to the Internet.
- Local system has RAS installed.
In this next example we are creating an instantiation of the “StateOfConnection “class, we will call the instance “MyState” and set the default value to 0.
This is where we actually call the external library and pass the two ref parameters. The external library returns a bool and that return value will be displayed in the txtFlag text box so you can visually see the results of the call.
Now that we have returned from the external library call we have an instantiated enumeration of the ConnectionState that we can access and retrieve its returned value. In this next example we are getting the value of the ConnectionState and displaying it in the txtState text box so you can visually see what was returned.
Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
We are well on our way to completing the application and testing our code to see if we can test for an Internet connection. In the next article we will show you the entire set of source code and how everything we have discussed actually works.
What have we learned?
Try Server Intellect for Windows Server Hosting. Quality and Quantity!
- Definition of Connection States
- How we call and utilize the external library
Continue reading Part Three here