当前位置: 代码迷 >> .NET面试 >> 帮小弟我写个服务,实现两台电脑定时通讯,证明都还活着(做心跳)
  详细解决方案

帮小弟我写个服务,实现两台电脑定时通讯,证明都还活着(做心跳)

热度:106   发布时间:2016-05-02 20:34:45.0
帮我写个服务,实现两台电脑定时通讯,证明都还活着(做心跳)
兄弟们,帮我写个例子

一个服务程序,定期与另一个ip的相同服务进行握手,如果某个时间段内发现没有握手(心跳),立刻报警(报警部分我可以自己写,呵呵)

我不想用socket通信,还要开放端口,不知道webservice行不行啊

不懂,多谢各位啦

用vs2005,高级版本的vs不符合我这里的开发要求

------解决方案--------------------
关于ASHX,我写了个小示例:

Example: Receive HTTP Post without web form via ASP.Net Generic Handler 
http://blog.csdn.net/xinyaping/article/details/7373017

贴出服务端的代码:

C# code
<%@ WebHandler Language="C#" Class="Echo" %>    using System;  using System.Web;  using System.IO;    public class Echo : IHttpHandler  {      private System.Text.Encoding DefaultEncoding = System.Text.Encoding.UTF8;            public void ProcessRequest (HttpContext context)      {          context.Response.ContentType = "text/plain";          context.Response.ContentEncoding = DefaultEncoding;            Stream inputStream = context.Request.InputStream;          using (StreamReader reader = new StreamReader(inputStream, DefaultEncoding))          {              string requestContent = reader.ReadToEnd();              string responseContent = string.Format("Received: {0} <== END", requestContent);                            context.Response.Write(responseContent);          }      }        public bool IsReusable      {          get { return false; }      }  }
  相关解决方案