?
Solved

Determining if a computer is online.

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

765 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