Otis,
Nowhere in your code do I see you set socket timeout. Connection timeout
determines the time HttpClient spends waiting a connection to be
established. The connection timeout does not affect socket I/O
operations. 

Try this:

_client.getHttpConnectionManager().getParams().setSoTimeout(5000);

Besides, we are just four bugs away from the first HttpClient 3.0 alpha
release when we formerly invite the users to review the new API. We'd be
more than interested to have your feedback.

Cheers,

Oleg



On Thu, 2004-05-06 at 19:50, [EMAIL PROTECTED] wrote:
> Hello,
> 
> I am using HttpClient from CVS HEAD from exactly 1 month ago (May 6,
> 2004).  Although I set the time-out to 5 seconds, I noticed that it
> does not always work, and because of that my application often hangs
> indefinitely.
> 
> Perhaps I'm not using the API correctly.
> Here are the relevant portions of my code:
> (HttpResponse is my class - a simple 'struct', nothing else)
> 
> 
> HttpClientParams clientParams = new HttpClientParams();
> clientParams.setParameter(HttpClientParams.USER_AGENT, "xxx");
> 
> _client = new HttpClient(clientParams);
> _client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
> 
> GetMethod method = new GetMethod(urlString);
> method.setFollowRedirects(false);
> 
> String responseBody = null;
> try {
>     _client.executeMethod(method);
>     responseBody = method.getResponseBodyAsString();
> } catch (HttpException he) {
>     System.err.println("Http error connecting to '" + url + "'");
>     method.releaseConnection();
>     method.recycle();
>     return new HttpResponse(-1, -1, null, null);
> } catch (IOException ioe) {
>     System.err.println("Unable to connect to '" + url + "'");
>     method.releaseConnection();
>     method.recycle();
>     return new HttpResponse(-1, -1, null, null);
> }
> 
> int statusCode = method.getStatusCode();
> long sizeBytes = method.getResponseContentLength();
> String charSet = method.getResponseCharSet();
> String lang    = null;
> 
> // clean up the connection resources
> method.releaseConnection();
> method.recycle();
> 
> return new HttpResponse(statusCode, sizeBytes, null, charSet);
> 
> 
> 
> Am I forgetting to call something that will ensure that no request ever
> hangs forever?
> 
> Thank you,
> Otis
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to