On Thu, 2004-05-06 at 20:33, [EMAIL PROTECTED] wrote:
> I like bleeding edge code, I'll try it as soon as you have it ready.
> I am now using the current HEAD and setting the timeout as you
> suggested.
> What is the difference between connection and socket timeout, and is
> connection timeout even needed if I set a socket timeout?
> 

Using the file system analogy, this is like opening a file and actually
reading data from it. TCP/IP is a complex protocol. It may take time to
set the communication channel up as it involves a fairly complex
handshake protocol. The socket connection timeout determines how long
one is prepared to wait for the channel to be up (think of file open).
The socket timeout determines how long a single read operation may take
(think of file read). After a successful read, the socket timeout is
reset, so that the next read starts from zero, not from where the
previous one left off. 

Hope this clarifies things a bit

Oleg




> Thanks,
> Otis
> 
> --- Oleg Kalnichevski <[EMAIL PROTECTED]> wrote:
> > 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]
> > 
> 
> 
> ---------------------------------------------------------------------
> 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