C # KeepAlive settings,
C # KeepAlive settings
There are a lot of KeepAlive related content on the Internet. Finally, I found this information about C # and set it to reliable!
TcpListener myListener = new TcpListener (IPAddress. any, port); // bind the port IP information myListener. start (); // Start listening for TcpClient newClient = myListener. acceptTcpClient (); // accept the request newClient. client. IOControl (IOControlCode. keepAliveValues, KeepAlive (1, 30000,100 00), null); // set the Keep-Alive parameter 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 ;}
Description of KeepAlive function parameters:
OnOff: whether to enable KeepAlive
KeepAliveTime: tcp null close time before the first KeepAlive test is started
KeepAliveInterval: interval between two KeepAlive probes
The location of Keep-Alive is set once for each connected client after receiving the client.
Related Articles: http://www.cnblogs.com/lidabo/p/4253356.html