Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Determining if a computer is online.

Posted on 2003-11-11
2
Medium Priority
?
244 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 1000 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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

610 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