Network Connection retention mechanism (Heartbeat mechanism to switch)

Source: Internet
Author: User
Tags keep alive
1. typedef struct stcpkeepalive2
2 .{
3. DWORD Onoff;
4. DWORD KeepAliveTime;
5. DWORD keepaliveinterval;
6.
7.} tcp_keep_alive2;
8.
9. Void setkeeplive (socket m_socket)
10 .{
11. Const char chopt = 1; // true
12. // set keepalive to enable the persistence mechanism to prevent the server from generating dead connections.
13. If (setsockopt (m_socket, sol_socket, so_keepalive, (char *) & chopt, sizeof (chopt) = 0)
14 .{
15. // set timeout details
16. tcp_keep_alive2 klive;
17. klive. Onoff = 1; // enable TTL
18. klive. KeepAliveTime = 1000*15; // 3-minute timeout keep alive
19. klive. keepaliveinterval = 1000*5; // the Retry Interval is 5 seconds. resend if no-reply
20. wsaioctl
21 .(
22. m_socket,
23. sio_keepalive_vals,
24. & klive,
25. sizeof (tcp_keep_alive2 ),
26. null,
27. 0,
28. (unsigned long *) & chopt,
29. 0,
30. null
31 .);
32 .}
33 .}

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.