我在尝试让 Android 应用程序(好吧,服务,它有任何区别)使用持久 HTTP 1.1 连接时遇到了问题。
以下循环(简化的测试用例)通过桌面 JRE 上的单个 TCP 会话工作,但在 Android 设备上会导致整个套接字创建/拆卸周期。
while (true) {
URL url;
try {
url = new URL("http://10.0.0.125:8080/SRV?");
URLConnection connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
}
Oracle 的 JDK 描述了一种叫做“系统属性”的东西:
http.keepAlive= 默认值:true
http.maxConnections= 默认值:5
在 Android 的运行时中是否有类似的东西阻止了持久连接的维护?