简体   繁体   English

如何关闭TCP Keepalive?

[英]How to turn TCP Keepalive off?

I have a java application acting aa server and an android phone acting as a client. 我有一个充当服务器的Java应用程序和一个充当客户端的android手机。 They are communicating over TCP sockets. 他们正在通过TCP套接字进行通信。

I often have the client sleep and when its buffer fills I want the wifi radio to be able to go to sleep. 我经常让客户端入睡,并且当其缓冲区已满时,我希望wifi无线电能够进入睡眠状态。 The problem is the client isn't sleeping. 问题是客户端没有在睡觉。 I noticed wireshark says my server is sending the a TCP KeepAlive packet approximately every half second so the wifi can't sleep. 我注意到Wireshark说我的服务器大约每半秒发送一次TCP KeepAlive数据包,以使wifi无法入睡。 I've tried the following on the server and client. 我已经在服务器和客户端上尝试了以下方法。

connectionSocket.setKeepAlive(false);

But this appears to change nothing. 但这似乎并没有改变。 I am using wireshark to analyze the traffic. 我正在使用Wireshark分析流量。 Here is a screen shot of wireshark... the black lines indicate where my client is asleep and it's receieve buffer is full. 这是wireshark的屏幕截图...黑色线条表示我的客户在哪里睡觉,并且接收缓冲区已满。 Can I stop the keepAlive packets from being sent by the server? 我可以阻止服务器发送keepAlive数据包吗?

Thanks! 谢谢!

TCP connections stay open until closed, the keep alive mechanism is here to detect connection failures. TCP连接一直保持打开状态直到关闭,这里的“保持活动”机制用于检测连接失败。

Check out this link: Does a TCP socket connection have a "keep alive"? 检查此链接: TCP套接字连接是否具有“保持活动”状态?

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

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