Return-Path: X-Original-To: apmail-hc-httpclient-users-archive@www.apache.org Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 59B58905B for ; Thu, 5 Jan 2012 04:42:08 +0000 (UTC) Received: (qmail 41837 invoked by uid 500); 5 Jan 2012 04:42:07 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 40594 invoked by uid 500); 5 Jan 2012 04:41:51 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 40575 invoked by uid 99); 5 Jan 2012 04:41:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2012 04:41:44 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,NORMAL_HTTP_TO_IP,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of srssreejith@gmail.com designates 209.85.212.179 as permitted sender) Received: from [209.85.212.179] (HELO mail-wi0-f179.google.com) (209.85.212.179) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2012 04:41:39 +0000 Received: by wibhm4 with SMTP id hm4so89367wib.10 for ; Wed, 04 Jan 2012 20:41:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=OAFyrnkB+LERaP8i7DiHaoEaUNm5dA2/IuRvhQ48vwE=; b=d89trpFX8o+jUVusETen9Jc3EW3nll7KFO3Ta6Ei8WFBrhPA+xt6pxro9T9R1X/qpX Xkf7enlFcx/MY3VnibM0a5jHBjbyMLkd8a65HMOmgyK99jjCKLylU9QnGDDUfaddF0aV v/Itz3hoMWDZOrqoLZxp/1MuRCHVkujKF3LgE= MIME-Version: 1.0 Received: by 10.181.13.179 with SMTP id ez19mr904244wid.11.1325738477344; Wed, 04 Jan 2012 20:41:17 -0800 (PST) Received: by 10.223.123.193 with HTTP; Wed, 4 Jan 2012 20:41:17 -0800 (PST) In-Reply-To: References: Date: Thu, 5 Jan 2012 10:11:17 +0530 Message-ID: Subject: Re: HttpClient connection time out , any defaults ?? From: Sreejith S To: HttpClient User Discussion Content-Type: multipart/alternative; boundary=f46d043d66d901d7a404b5c08bd2 --f46d043d66d901d7a404b5c08bd2 Content-Type: text/plain; charset=ISO-8859-1 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 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 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 > > --------------------------------------------------------------------- > 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 --f46d043d66d901d7a404b5c08bd2--