简体   繁体   English

如何防止Winsock应用程序由于网络不活动而断开连接(C ++)

[英]How to prevent winsock application from disconnecting due to network inactivity (c++)

Currently have a winsock application that connects to a server. 当前有一个连接到服务器的Winsock应用程序。 It can send and receive packets, but after a few minutes(around 2, if you wanted me to guess) of not sending anything, it disconnects and I have restart it, which is pretty annoying. 它可以发送和接收数据包,但是几分钟(大约2个,如果您想让我猜)之后什么也没发送,它断开连接,我已经重新启动它,这很烦人。 Thanks in advance. 提前致谢。

You can try setting KEEPALIVE to true. 您可以尝试将KEEPALIVE设置为true。 You set this using the socket options. 您可以使用套接字选项进行设置。 You have to set it on both the client socket and the server's listening socket. 您必须在客户端套接字和服务器的侦听套接字上都进行设置。

Have a look at: http://linux.die.net/man/2/setsockopt And http://msdn.microsoft.com/en-us/library/windows/desktop/ms740476(v=vs.85).aspx 看看: http : //linux.die.net/man/2/setsockopthttp://msdn.microsoft.com/zh-cn/library/windows/desktop/ms740476(v=vs.85)。 aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM