hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sreejith S <srssreej...@gmail.com>
Subject Re: HttpClient connection time out , any defaults ??
Date Thu, 05 Jan 2012 04:41:17 GMT
Thank you Vasile,

Pls check out my code . What i need to do is , establish a connection to a
url using HttpClient and if there is some connection problems untill a time
out value , then HttpClient should close the connection.

This is my code snippet

      HttpParams httpParams = new BasicHttpParams();
      HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);

      // set request params
      httpParams.setParameter("http.language.Accept-Language", "en-us");
      httpParams.setParameter("http.protocol.content-charset", "UTF-8");
      httpParams.setParameter("Accept",
"application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
      httpParams.setParameter("http.connection.stalecheck", false); // turn
off stale check checking for performance reasons


      SchemeRegistry schemeRegistry = new SchemeRegistry();
      schemeRegistry.register(new Scheme("http", 80,
PlainSocketFactory.getSocketFactory()));
      schemeRegistry.register(new Scheme("https", 443,
SSLSocketFactory.getSocketFactory()));

      final ThreadSafeClientConnManager cm = new
ThreadSafeClientConnManager(schemeRegistry);
      httpClient = new DefaultHttpClient(cm, httpParams);

      HttpConnectionParams.setConnectionTimeout(httpParams, 1000);
      HttpConnectionParams.setSoTimeout(httpParams, 10000);

      httpClient.getParams().setParameter("http.connection.timeout", 1000);
      httpClient.getParams().setParameter("http.tcp.nodelay", true);


and this is my log
2012-01-04 11:12:05 HtmlFetch [DEBUG] Initializing HttpClient
2012-01-04 11:12:05 SingleClientConnManager [DEBUG] Get connection for
route HttpRoute[{}->http://192.168.2.59]
2012-01-04 11:12:05 DefaultClientConnectionOperator [DEBUG] Connecting to
192.168.2.59:80
2012-01-04 11:12:05 RequestAddCookies [DEBUG] CookieSpec selected:
best-match
2012-01-04 11:12:05 RequestAuthCache [DEBUG] Auth cache not set in the
context
2012-01-04 11:12:05 DefaultHttpClient [DEBUG] Attempt 1 to execute request
2012-01-04 11:12:05 DefaultClientConnection [DEBUG] Sending request: GET
/test.php HTTP/1.1
2012-01-04 11:12:05 wire [DEBUG] >> "GET /test.php HTTP/1.1[\r][\n]"
2012-01-04 11:12:05 wire [DEBUG] >> "Host: 192.168.2.59[\r][\n]"
2012-01-04 11:12:05 wire [DEBUG] >> "Connection: Keep-Alive[\r][\n]"
2012-01-04 11:12:05 wire [DEBUG] >> "User-Agent: Apache-HttpClient/4.1.2
(java 1.5)[\r][\n]"
2012-01-04 11:12:05 wire [DEBUG] >> "[\r][\n]"
2012-01-04 11:12:05 headers [DEBUG] >> GET /test.php HTTP/1.1
2012-01-04 11:12:05 headers [DEBUG] >> Host: 192.168.2.59
2012-01-04 11:12:05 headers [DEBUG] >> Connection: Keep-Alive
2012-01-04 11:12:05 headers [DEBUG] >> User-Agent: Apache-HttpClient/4.1.2
(java 1.5)
2012-01-04 11:12:15 wire [DEBUG] << "HTTP/1.1 200 OK[\r][\n]"
2012-01-04 11:12:15 wire [DEBUG] << "Date: Wed, 04 Jan 2012 05:42:05
GMT[\r][\n]"
2012-01-04 11:12:15 wire [DEBUG] << "Server: Apache/2.2.17 (Ubuntu)[\r][\n]"
2012-01-04 11:12:15 wire [DEBUG] << "X-Powered-By:
PHP/5.3.5-1ubuntu7.4[\r][\n]"
2012-01-04 11:12:15 wire [DEBUG] << "Vary: Accept-Encoding[\r][\n]"
2012-01-04 11:12:15 wire [DEBUG] << "Content-Length: 0[\r][\n]"
2012-01-04 11:12:15 wire [DEBUG] << "Keep-Alive: timeout=15,
max=100[\r][\n]"
2012-01-04 11:12:15 wire [DEBUG] << "Connection: Keep-Alive[\r][\n]"
2012-01-04 11:12:15 wire [DEBUG] << "Content-Type: text/html[\r][\n]"
2012-01-04 11:12:15 wire [DEBUG] << "[\r][\n]"
2012-01-04 11:12:15 DefaultClientConnection [DEBUG] Receiving response:
HTTP/1.1 200 OK
2012-01-04 11:12:15 headers [DEBUG] << HTTP/1.1 200 OK
2012-01-04 11:12:15 headers [DEBUG] << Date: Wed, 04 Jan 2012 05:42:05 GMT
2012-01-04 11:12:15 headers [DEBUG] << Server: Apache/2.2.17 (Ubuntu)
2012-01-04 11:12:15 headers [DEBUG] << X-Powered-By: PHP/5.3.5-1ubuntu7.4
2012-01-04 11:12:15 headers [DEBUG] << Vary: Accept-Encoding
2012-01-04 11:12:15 headers [DEBUG] << Content-Length: 0
2012-01-04 11:12:15 headers [DEBUG] << Keep-Alive: timeout=15, max=100
2012-01-04 11:12:15 headers [DEBUG] << Connection: Keep-Alive
2012-01-04 11:12:15 headers [DEBUG] << Content-Type: text/html
2012-01-04 11:12:15 ThreadSafeClientConnManager [DEBUG] Shutting down
2012-01-04 11:12:15 DefaultHttpClient [DEBUG] Connection can be kept alive
for 15000 MILLISECONDS
2012-01-04 11:12:15 SingleClientConnManager [DEBUG] Releasing connection

Here DefaultHttpClient [DEBUG] Connection can be kept alive for 15000
MILLISECONDS . Is this default time out ???

Thank You,

On Wed, Jan 4, 2012 at 7:06 PM, Vasile Alin <alinachegalati@gmail.com>wrote:

> Connection timeout and keep alive timeout are different things.
>
> Connection timeout determines the timeout until a connection is
> established at client side and the  keep-Alive timeout determines the
> timeout to close an idle connection, at server side.
>
> You can see more about keep-alive in the RFC2616 spec:
> http://tools.ietf.org/html/rfc2616#section-8.1
>
> Alin
>
> P.S. You should include your code snippets and logs in the mail body.
>
> On 4 January 2012 07:59, Sreejith S <srssreejith@gmail.com> wrote:
> > Hi all,
> >
> > I am using httpclient from org.apache.httpcomponents and the version is
> > 4.1.2.
> >
> > I have some problems with the connection time out of HttpClient.Even if i
> > am setting connection time out as 1000 ms , the connection will keep
> alive
> > for 10 secs by defalut.
> > Pls check out my pastebin for the code snippet and log.
> > http://pastebin.com/W0PpzmWu
> >
> > Thank you,
> >
> > --
> >
> >
> > *Sreejith.S*
> > http://srijiths.wordpress.com/
> > * *http://sreejiths.emurse.com/
> >
> > tweet2sree@twitter <http://tweet2Sree>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 


*Sreejith.S*
http://srijiths.wordpress.com/
* *http://sreejiths.emurse.com/

tweet2sree@twitter <http://tweet2Sree>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message