定期检查服务器启动状态 [英] Check Server Up status periodically

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

问题描述

我有基于C#的客户端-服务器体系结构.客户端将连接到服务器并交换数据.

我需要连续检查服务器状态,并且服务器是否关闭(从网络中删除或关闭),我需要指示客户端.

如何监控呢?

如果我在客户端程序中使用Ping实用程序,这将是性能方面的最佳方法,即通过单独的线程或通过后台类进行监视?

I have C# based client-server architecture. Client will connect to server and exchange data.

I need to check the server status continuously and if the server goes down (removed from network or shut down) i need to indicate the client.

How to monitor this??

If I am using Ping utility in client program, which will be the best method in terms of performance i.e, monitor via a separate thread or through a background class??

public static bool GetPingResponse(string IpAddress, int timeout = 3000)
        {
            var ping = new Ping();
            var reply = ping.Send(IpAddress, timeout); 
            if (reply.Status == IPStatus.Success)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


在性能和消耗资源方面,还有没有其他比Ping更好的选择了?


Is there any other option better than Ping in terms of performance and consuming the resource??

推荐答案

Ping几乎是您可以在两台计算机之间进行的最小通信:字面意思是你在那儿吗?" 是",因此很难缩短任何内容!

我将设置一个BackGroundWorker,该线程使用Thread.Sleep自行关闭十秒钟(或无论您的报告周期如何),然后执行Ping操作,并通过ReportProgress方法报告成功或失败.
A Ping is pretty much the minimum communications you can do between two computers: it is literally "Are you there?" "Yes" so it is difficult to get anything shorter!

I would set up a BackGroundWorker which used Thread.Sleep to turn itself off for ten seconds (or whatever your reporting period is) then does a Ping, and reports back success or fail via the ReportProgress method.


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

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