tags:

views:

1119

answers:

3

Hello,

C# 2008

I have developed a softphone application.

However, I have to test for a constant internet connection.

I was thinking of having a function that runs in another thread that constantly pings a IP address. However, what IP address can I used to determine if my application is still connected to the Internet.

Many thanks,

+1  A: 

Please see this SO question and answer: C# - How do I check for a network connection

If you are restricted to the .NET Compact Framework, check out the free OpenNETCF library.

Mitch Wheat
That will tell you if the LAN is available, but not if the WAN is (for example, if you're behind a NAT firewall)
Rowland Shaw
return NetworkInterface.GetIsNetworkAvailable(); Just tested. It will always return true.
robUK
+1  A: 

Do you just want to check if there is a network connection, or if the network actually goes out to the internet.

In the first case, then do as it says in the "How do I check for an network connection question". This will let you know if the cable gets pulled out of the back of your PC, but its won't tell you if your modem or phone line is malfunctioning (for example)

The second case is more complicated, as far as I know, there is no way to check this apart from constantly polling some IP address. In the simple case, you could just have a Timer ping some website every 30 seconds in a separate thread, and raise events when it decides the internet is down. Be aware that ICMP pings are not 100% reliable though, occasionally they will get dropped even if your connection is ok.

If you really wanted to get complicated you could create a windows service raising these events, then multiple applications could hook in and consume the information, but thats a bit beyond my knowlage of windows programming though.

Nathan Reed
I used that sample code. However, I am currently on the wireless. So when I turned my wireless off. It still returned true. Is this correct. Currently I don't have any Lan cable to connect to my network code. Only wireless.
robUK
+1  A: 

I would of thought telneting to to port 80 of www.google.com would be your best bet.

If the connection is open the all is well.

Not sure how easy this would be to implement in the cf though.