Solved

Determining if a computer is online.

Posted on 2003-11-11
2
239 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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