Solved

Determining if a computer is online.

Posted on 2003-11-11
2
226 Views
Last Modified: 2010-04-16
I am trying to determine if a computer is online.  I do this before every server call so I can determine if the server is down, or the client is not connected.  This method does not work for two reasons:  1.  It takes forever to timeout if the computer is offline.  2.  the call doesn't work if you do it too many times in a row (for hammering protection) even if you are online.

Is there a native method I can call or something that will work better?

public static bool ComputerOnline()
{
          System.Net.HttpWebRequest wr = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://google.com/");
          try            
          {
      System.Net.HttpWebResponse ws = (System.Net.HttpWebResponse)wr.GetResponse();
      return true;
          }
          catch
          {
      return false;
          }
}
0
Comment
Question by:jjacksn
2 Comments
 
LVL 6

Expert Comment

by:martinv
ID: 9727161
There could be several ways how to make it faster:

- use IP address instead of DNS. DNS resolving can take some time, and if you are offline DNS server timeout can be long.

- if you want to know that computer is live (and not it's webserver) use PING instead of getting web server response. For ping class see http://www.eggheadcafe.com/articles/20020209.asp  (you may want to remove Dns.GetHostByName calls from the source code)
0
 
LVL 18

Accepted Solution

by:
testn earned 250 total points
ID: 9727179
To check whether the client is online
http://www.csharphelp.com/archives3/archive499.html
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now