Solved

Determining if a computer is online.

Posted on 2003-11-11
2
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 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