HTTP连接超时的问题 [英] http connection timeout issues
问题描述
我运行到一个问题,当我尝试使用HttpClient的连接 到URL。 HTTP连接正在采取更长的时间超时,我设置即使 连接timeoout。
I'm running into an issue when i try to use the HttpClient connecting to a url. The http connection is taking a longer time to timeout, even after i set a connection timeoout.
int timeoutConnection = 5000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
它的工作原理完美的大部分时间。然而,每一次的同时,HTTP连接运行,直到永忽略 setconnectiontimeout
,especailly当手机连接到无线网络,并且手机在空转。
It works perfect most of the time. However, every once in while, the http connection runs for ever and ignore the setconnectiontimeout
, especailly when the phone is connected to wifi, and the phone was idling.
打完电话空转,我第一次尝试连接,HTTP连接忽略 setconnectiontimeout
和将永远运行下去,以后我取消它,然后再试一次,它就像每次魅力。但是,一个不工作的时候它会创建一个 threadtimeout
的错误,我尝试使用不同的线程,它的工作原理,但我知道,线程运行很长一段时间。
So after the phone is idling, the first time i try to connect, the http connection ignores the setconnectiontimeout
and runs forever, after i cancel it and try again, it works like charm everytime. But that one time that doesn't work it creates a threadtimeout
error, i tried using a different thread, it works, but i know that the thread is running for long time.
据我所知,在WiFi进入睡眠状态的闲置,但我不明白为什么它忽略了 setconnectiontimeout
。
I understand that the wifi goes to sleep on idle, but i dont understand why its ignoring the setconnectiontimeout
.
任何人都可以帮忙,ID真的AP preciated。
Anyone can help, id really appreciated.
推荐答案
不知道这是否可以帮助你,但我认为这是值得分享这里。在播放与暂停的东西,我发现还有第三种超时类型可分配:
Not sure if this helps you, however I think it's worth sharing here. While playing with the timeout stuff I found there is a third timeout type you can assign:
// the timeout until a connection is established
private static final int CONNECTION_TIMEOUT = 5000; /* 5 seconds */
// the timeout for waiting for data
private static final int SOCKET_TIMEOUT = 5000; /* 5 seconds */
// ----------- this is the one I am talking about:
// the timeout until a ManagedClientConnection is got
// from ClientConnectionRequest
private static final long MCC_TIMEOUT = 5000; /* 5 seconds */
...
HttpGet httpGet = new HttpGet(url);
setTimeouts(httpGet.getParams());
...
private static void setTimeouts(HttpParams params) {
params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
CONNECTION_TIMEOUT);
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, SOCKET_TIMEOUT);
params.setLongParameter(ConnManagerPNames.TIMEOUT, MCC_TIMEOUT);
}
这篇关于HTTP连接超时的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!