How to detect connection?

Started by
2 comments, last by garywg 23 years, 6 months ago
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?
Advertisement
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 .
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.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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.

This topic is closed to new replies.

Advertisement