如何设置在Android上端的超时时间? [英] How to set the keepalive timeout in Android?

查看:651
本文介绍了如何设置在Android上端的超时时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想降低TCP存活时间在一个Socket,我十分钟顺序开放2小时的东西。我可以把它使用的存活与socket的(真正的),但我怎么能控制keepalive报文发送之前的时间?

I'd like to lower the TCP keepalive time on a Socket I'm opening from 2 hours to something on the order of ten minutes. I can make it use keepalive with socket.setKeepAlive(true), but how can I control the time before a keepalive packet is sent?

它看起来像我可以,如果我用的是NDK做到这一点,但我想分发此code作为一个罐子,所以这不是理想的我。

It looks like I could do this if I was using the NDK, but I want to distribute this code as a jar, so that's not ideal for me.

推荐答案

这可能是太明显了一个答案[即它不是针对特定的情况选择],但你当然可以通过发送1扔掉的字节(在两个方向),每10分钟实现自己的存活。

This is probably too obvious an answer [i.e. it's not an option for your specific case] but you can of course implement your own keepalive by sending 1 throw-away byte (in either direction) every 10 minutes.

这篇关于如何设置在Android上端的超时时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆