Checking if a network connection is available

Hi there,

What is the best way to check if a network connection is available?
Right now I just try to connect and let it fail, and when it does fail it knows the connection is not available and continues in ‘off-line mode’.
Problem with that is that my game is full screen openGL and when you’re on dial-up, windows will pop up a dialog asking if you would like to dial in. This results in annoyingly getting back to windows in another resolultion where you have to answer the dialog after which it returns to full screen again.

Is there any other way to prevent this?

Erik

This is not your problem… it’s a windows config problem. In the internet options, there is a tab ‘Connections’, set the option:
Never dial a connection.

I had the same annoying behavior with a game that ewanted to register itself somewhere in the net…

One option to kwnow if you are in a network is to count how many IPs your computer has, if more than one… (127.0.0.1) maybe you are online… Just a idea…

Rafael

That’s what I do - there’s a util class in SPGL (CheckOnline or something) that looks for any IP address that isn’t the local host. Works a treat. It doesn’t actually check internet access, only network access.

Cas :slight_smile:

Cas,

Wouldn’t that return true if you had a network adapter installed without DHCP even if it weren’t connected to the net?

Yes, but it’s the best you can do without actually attempting a connection. For 99% of systems out there the presence of a non-local IP address means a LAN or dialup is present.

Looks like a candidate API for the LWJGL; in Windows there’s actual API to connect to the internet. Not sure about MacOS.

Cas :slight_smile:

There is no one best answer to this question. It may be best to ask the user during install what type of connection they use and then adjust the strategy accordingly.
You can detect an active modem connection by enumerating the list of network interfaces and finding something that wasn’t there before (or previously had a zero address). If the address is in a public range it is probably connected to the internet.
If there is a UPnP gateway on the local network you can detect that using UPnP queries (can be done in pure java), and then ask what IP is on the other side of the gateway.
People with on demand ISDN routers may get justifiably annoyed if you attempt connections without asking in areas with expensive charging structures.

I understand though that UPnP is seriosuly flawed in terms of security… I don’t know the details thats just what I’ve heard.

Which is too bad because I have been saying for about 2 years whats needed for games is a standard way for them to negotiate with the firewall directly. sigh

UPnP may be flawed but it is out there and we can use it when available. Given that it can usually only be controlled from the inside, the only flaw I can see is that any opened ports remain open for a while after the aplication that opened them terminates. Also if you do get infected by a virus then it can easily open any ports it wants and most people would never notice.

Yes, but the “when its available” is indeed the key.
based on security wranings from folks I trust I routinely disable it. I don’t know how many others do the same.

Every time a WinXP box booted on my home network, it used uPnP to open holes through my router’s firewall…

In my house at least, uPnP is culled wherever it is found. ;D