1

I have a windows service that will connect to a WCF web service is due course. However, I like to see if the client has COMs (internet) available before attempt of a connection is made to my own web service. Pinging from the window service seems a good way of doing this. (its fast)

Are there any tutorials or example code out there I could see so I can do this?

Thanks

user3428422
  • 4,300
  • 12
  • 55
  • 119
  • you should consider to think about your actual question in a more generic matter. http://stackoverflow.com/questions/20309158/c-sharp-checking-internet-connection http://stackoverflow.com/questions/2031824/what-is-the-best-way-to-check-for-internet-connectivity-using-net – Dbl Jul 03 '14 at 15:22
  • " client has COMs (internet) "? What is that "COM" you are interested in? (Clearly you've serched if [Ping class](http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping%28v=vs.110%29.aspx) exist - so please add in formation what errors/problems you've got using it. – Alexei Levenkov Jul 03 '14 at 15:23
  • I am not entirely sure why is hasnt been deleted yet if 4 users has considered it as off-topic? I could delete it now in seconds.. I have no issue with this and will apologise for posting the question, but why keep it on stack overflow... a strange protocol – user3428422 Jul 04 '14 at 07:17

2 Answers2

4

This should do it

using(System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping())
{
    {
    try
    {
        System.Net.NetworkInformation.PingReply reply = p.Send("127.0.0.1", 3000);
        if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
            return true;
    }
    catch(Exception ex) 
    {

    }
}
Captain Kenpachi
  • 6,960
  • 7
  • 47
  • 68
2

Lucky for you there is a ping class in .net. However this will only work if icmp is working on the remote server. I don't know if that will give you more then just attempting to connect.

Daniel Kelley
  • 7,579
  • 6
  • 42
  • 50
rerun
  • 25,014
  • 6
  • 48
  • 78