在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
C# KeepAlive的相关设置 网上有很多相关KeepAlive的内容,终于找到了有关C#的这方面资料,设置了下,有行可靠! TcpListener myListener = new TcpListener(IPAddress.Any, port);//绑定端口IP信息 myListener.Start();//开始监听 TcpClient newClient=myListener.AcceptTcpClient();//接受请求 newClient.Client.IOControl(IOControlCode.KeepAliveValues, KeepAlive(1, 30000, 10000), null);//设置Keep-Alive参数 private byte[] KeepAlive(int onOff, int keepAliveTime, int keepAliveInterval) { byte[] buffer = new byte[12]; BitConverter.GetBytes(onOff).CopyTo(buffer, 0); BitConverter.GetBytes(keepAliveTime).CopyTo(buffer, 4); BitConverter.GetBytes(keepAliveInterval).CopyTo(buffer, 8); return buffer; }
Keep-Alive的位置我是放在收到客户端以后,对每个连入的客户端都设置一次。
相关文章:http://www.cnblogs.com/lidabo/p/4253356.html
|
请发表评论