checking if there is an internet connection?

Started by
4 comments, last by mutex 19 years, 1 month ago
Is there a way to check if there is an internet connection on a PC?
Advertisement
Try opening a connection to your server's ip address.
++Alex
Ask the user. If they connect through dialup, they may not be connected currently but may want to, and in any case may have very particular ideas regarding whether they want your program accessing the internet or not.
I'm making an application that needs to open a certain website. So can't I just check myself if there is an internet connection or not? If not I can warn the user that I will not be able to connect to that website?
Again: just ask the user. That way, he'll either know that your program is accessing a website, or be able to decide that it shouldn't.

If the access is caused by a user's explicit action and should be obvious (like if the user selected "Open MyProgram home page..." from the help menu) then you can reasonably assume that the user wants you to make a connection and that you are able to. Otherwise, ask.
There appear to be Windows functions to do this sort of stuff. Check out InternetCheckConnection to determine if you can connect to a website. Or you can try creating a socket and connecting manually, but this is probably simpler. There's also InternetGetConnectedState to determine the Internet connection state, as well as functions to connect via dialup. The documentation seems light on details, though.

This topic is closed to new replies.

Advertisement