C # KeepAlive settings,

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.