Archived

This topic is now archived and is closed to further replies.

garywg

How to detect connection?

Recommended Posts

I want to know how to detect a network connection(like icq), I try to use InternetGetConnectState() function, but when I try it on the PC connect to a LAN, even it did not connect to the Internet it return true. Is there any other method?

Share this post


Link to post
Share on other sites
There are several methods, i prefer to use the win32 api function:
RasEnumConnections()
this will return all active RAS connections. There are enough samples online that will demonstrate how to use it.

Another method is to ping a server on the internet, for example altavista.com .

Share this post


Link to post
Share on other sites
this gets really complicated:

I assume the goal is to detect a valid un-obstructed (not proxied or overly-restricted NAT) internet connection?

I can think of four cases:
Computer has no NICs, no modems
No connection possible
Computer has no NICs, at least one modem
RAS user, need to dial&connect to ISP then connect
Computer has at least one NIC, no modems
They either have a route out or they don''t, attempt connection
Computer has at least one NIC, at least one modem
Who knows. Try both


Generally you should just attempt to connect, and if the user needs to dial they either need to know to connect first, or have auto-connect enabled.

Share this post


Link to post
Share on other sites
Well, you could have them specify how they connect to the internet when installing, present them with a list of interfaces retrieved from the IP Helper API and add any RAS entries to the list also, then just check the state of whatever they select when your game starts.

Share this post


Link to post
Share on other sites