.net socket异步通讯的心跳机制

.net socket异步通讯的心跳机制,通常有两种:1.自己来写2.用tcp协议的机制keepalive.

如:

//设置系统心跳
uint dummy = 0;
byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3];
BitConverter.GetBytes((uint)1).CopyTo(inOptionValues, 0);
BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy));   //多长时间开始发心跳
BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2);//每隔多少时间发一次
newsock.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null);

 

posted @ 2012-07-13 13:42  tianyuxipeng  阅读(368)  评论(0编辑  收藏  举报