Re: HttpURLConnection timeout?



Dave Ockwell-Jenner wrote:
Jack wrote:

Hi,

Is it possible to set a timeout when opening a connection to an
HttpURLConnection?

For example, is it possible to make the connection call and limit it to 5
seconds before a response is generated?

That is, I don't want to have to wait for the "default" timeout.

[snip]

You can't do this using Sun's classes unless you use a "private" property setting. Unfortunately, the setting is not guaranteed to remain the same (or remain at all).

I've just been working on a similar task and used the Commons-HTTPClient[1] from Apache. It allows you to specify both a connection timeout and also a timeout when reading the response. It works superbly!

[1] http://jakarta.apache.org/commons/httpclient/

Actually Sun has added this in Java 1.5. See the java.net.URLConnection setConnectionTimeout() and setReadTimeout() methods. If you need to use an earlier version of Java then the Jakarta HTTPClient package works great.
.




Relevant Pages

  • Re: OE6 does not connect with pop3 server
    ... Can we infer from this that you got a timeout on the EarthLink account ... My point about making an approximate timestamp is just to look at the ... E.g. as near as possible before the connection ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Timout control with RPC/HTTP
    ... specifies the minimum connection timeout used by the ... client and RPC Proxy, in seconds. ... Microsoft CSS Online Newsgroup Support ...
    (microsoft.public.exchange.admin)
  • Re: Timout control with RPC/HTTP
    ... please also check the RPC web site connection timeout settings ... Maybe the idle timeout settings depend on here. ...
    (microsoft.public.exchange.admin)
  • Re: web serivce: client side timeout?
    ... client side but only from the server side. ... System.Net.Sockets.SocketException: A connection attempt failed ... asyncResult, Int32 timeout, Exception& exception) ... John Saunders | MVP - Windows Server System - Connected System ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Timout control with RPC/HTTP
    ... But it is a IDLE timeout period that I am looking to control. ... But when they are idel the connection status will say - " last updated ...." ... Where do I control the settings for outlook to reconnect to the server to see if the mailbox is in sync with the remote lcoal cache. ... Microsoft CSS Online Newsgroup Support ...
    (microsoft.public.exchange.admin)