检查服务器是否可用

编程入门 行业动态 更新时间:2024-10-06 15:28:36
本文介绍了检查服务器是否可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在寻找一种方法来检查服务器是否仍然可用。我们有一个离线应用在服务器上保存的数据,但如果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", 60 * 1000); // 1 minute time out (in ms) // or... reply = ping.Send(new IPAddress(new byte[]{127,0,0,1}), 3000);

更多推荐

检查服务器是否可用

本文发布于:2023-11-23 21:51:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622948.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!