hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: How to ensure socket reuse on client side?
Date Wed, 08 Nov 2006 21:39:54 GMT
On Thu, 2006-11-09 at 04:46 +0800, umesh409@yahoo.com wrote:
> I am new to HttpCore and using 4.0 Alpha 2 version. I am trying to connect a server and
request more than one pages from that server using the same connection. My goal is to reuse
socket so that no new socket is opened on the Http client for the subsequent requests to the
same server and port.
> 

...


>                System.out.println(">> Response: " + response.getStatusLine());
> 
>                
> 
>                Header[] hds = response.getAllHeaders();
> 
>                for (Header h: hds){
> 
>                   System.out.println(">> Headers Name: " + h.getName() + 
> 
>                         " Value: " + h.getValue() );
> 
>                }
> 

You should consume the entire response content in order to be able to
reuse the connection. This additional line fixes the problem

---
String stuff = EntityUtils.toString(response.getEntity());
---

Just out of curiosity why are using HttpCore and not HttpClient 3.x?

Oleg 

>                
> 
>                System.out.println("==============");
> 
>                
> 
>                if (!connStrategy.keepAlive(response)) {
> 
>                   System.out.println("Connection closed.");
> 
>                   conn.close();
> 
>                } else {
> 
>                   conn.flush();
> 
>                   System.out.println("Connection kept alive...");
> 
>                }
> 
...


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


Mime
View raw message