Android上的DefaultHttpClient中的连接和套接字超时的默认值是什么? [英] What are default values for connection and socket timeouts in DefaultHttpClient on Android?

查看:90
本文介绍了Android上的DefaultHttpClient中的连接和套接字超时的默认值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android 2.1/2.2上,我使用Android SDK中的DefaultHttpClient.

On Android 2.1/2.2 I use DefaultHttpClient found in Android SDK.

Apache在他们的文档中说有2个超时:

Apache says in their docs there are 2 timeouts:

  • CoreConnectionPNames.SO_TIMEOUT ='http.socket.timeout':以毫秒为单位定义套接字超时(SO_TIMEOUT),这是等待数据的超时,或者换句话说,是最大的两个连续数据包之间的周期不活动).超时值为零将被解释为无限超时.该参数需要一个java.lang.Integer类型的值.如果未设置此参数,则读取操作将不会超时(无限超时).

  • CoreConnectionPNames.SO_TIMEOUT='http.socket.timeout': defines the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets). A timeout value of zero is interpreted as an infinite timeout. This parameter expects a value of type java.lang.Integer. If this parameter is not set, read operations will not time out (infinite timeout).

CoreConnectionPNames.CONNECTION_TIMEOUT ='http.connection.timeout':确定建立连接之前的超时时间(以毫秒为单位).超时值为零将被解释为无限超时.该参数需要一个java.lang.Integer类型的值.如果未设置此参数,则连接操作将不会超时(无限超时).

CoreConnectionPNames.CONNECTION_TIMEOUT='http.connection.timeout': determines the timeout in milliseconds until a connection is established. A timeout value of zero is interpreted as an infinite timeout. This parameter expects a value of type java.lang.Integer. If this parameter is not set, connect operations will not time out (infinite timeout).

我尝试在Android源中搜索这两个超时的默认值,但找不到.有谁知道这些超时的默认值是多少?我想获得指向设置了值的资源的链接,或与此有关的官方文档(而只是为了听取意见).

I tried searching Android sources for default values for these 2 timeouts, but was unable to find. Does anyone know what are the default values for these timeouts? I'd like to get a link to sources where the values are set or an official doc on this (versus just to hear an opinion).

推荐答案

只需尝试以下代码段:

import android.net.http.AndroidHttpClient;
...
        AndroidHttpClient h = AndroidHttpClient.newInstance("My http client");
        // ...
        Log.d(TAG, "http.socket.timeout: " + h.getParams().getParameter("http.socket.timeout"));
        Log.d(TAG, "http.connection.timeout: " + h.getParams().getParameter("http.connection.timeout"));

它可以在我的设备上运行:

It works on my device:

12-02 16:27:54.119 D/Exam(17121): http.socket.timeout: 60000
12-02 16:27:54.119 D/Exam(17121): http.connection.timeout: 60000

这篇关于Android上的DefaultHttpClient中的连接和套接字超时的默认值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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