检查服务器是否可用 [英] Check if a server is available

查看:225
本文介绍了检查服务器是否可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来检查服务器是否仍然可用。
我们有一个离线应用在服务器上保存的数据,但如果serverconnection下降(它偶尔发生),我们将数据保存到本地数据库,而不是在线数据库。
因此,我们需要一个继续检查服务器是否仍然可用。

I'm looking for a way to check if a server is still available. We have a offline application that saves data on the server, but if the serverconnection drops (it happens occasionally), we have to save the data to a local database instead of the online database. So we need a continues check to see if the server is still available.

我们使用C#这个应用

支票上的 sqlconnection.open 是不是一个真正的选择,因为这需要大约20秒之前发生错误时,我们不能等待这么长的+我中号使用一些HTTP服务也是如此。

The check on the sqlconnection.open is not really an option because this takes about 20 sec before an error is thrown, we can't wait this long + I'm using some http services as well.

推荐答案

只需使用的 System.Net.NetworkInformation.Ping 类。如果服务器没有响应ping(由于某种原因,你决定封锁ICMP回应请求),你必须创造你自己的服务这一点。就个人而言,我完全不阻止ICMP回应请求,我认为这是要走的路。 ping命令已被用于年龄检查主机的可达

Just use the System.Net.NetworkInformation.Ping class. If you server does not respond to ping (for some reason you decided to block ICMP Echo request) you'll have to invent you own service for this. Personally, I'm all for not blocking ICMP Echo requests, and I think this is the way to go. The ping command has been used for ages to check reachability of hosts.

using System.Net.NetworkInformation;
var ping = new Ping();
var reply = ping.Send("google.com", 60 * 1000); // 1 minute time out (in ms)
// or...
reply = ping.Send(new IPAddress(new byte[]{127,0,0,1}), 3000);

这篇关于检查服务器是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆