Related Settings for C # keepalive
Online has a lot of relevant keepalive content, finally found about C # in this aspect of information, set up under, there is reliable!
TcpListener MyListener = new TcpListener (Ipaddress.any, port);//Binding port IP Information mylistener.start ();//Start listening TcpClient Newclient=mylistener.accepttcpclient ();//Accept Request NewClient.Client.IOControl (Iocontrolcode.keepalivevalues, KeepAlive (1, 30000, 10000), NULL);//Set keep-alive parameter private byte[] KeepAlive (int onOff, int keepalivetime, int Keepalivein Terval) { 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; }
KeepAlive函数参数说明:
onOff:是否开启KeepAlive
keepAliveTime:开始首次KeepAlive探测前的TCP空闭时间
keepAliveInterval: 两次KeepAlive探测间的时间间隔
Keep-alive location I put it on. Once the client is received, it is set once for each client that is connected.
Related article: http://www.cnblogs.com/lidabo/p/4253356.html
Settings for C # keepalive