vinay_delhi
asked on
Setting connection timeout with HttpURLConnection
I am using :
URL url = new URL(<some url>);
HttpURLConnection huc= (HttpURLConnection) url.openConnection();
I want the connection to close if its not able to establish connction (or anything goes wrong during getting connection) afer a given amount of time. I don't want it to hang up the connection for ever.
How can I do that ?
Thanks.
URL url = new URL(<some url>);
HttpURLConnection huc= (HttpURLConnection) url.openConnection();
I want the connection to close if its not able to establish connction (or anything goes wrong during getting connection) afer a given amount of time. I don't want it to hang up the connection for ever.
How can I do that ?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CEHJ> At least, it can be done quite effectively in 1.3.
Then post how.
My suggestioon would be to use a decent http implementation that provides support for timeout such as HTTPClient.
Then post how.
My suggestioon would be to use a decent http implementation that provides support for timeout such as HTTPClient.
>>Then post how.
Already been posted
Already been posted
They are not available in 1.3.
I can assure you they are - I use them all the time
u must be running 1.4 then
No - i tell a lie. Those *are* the 1.4 timeout properties, but there's also one for 1.3 as well - but i'm damned if i can find it at the moment
> but there's also one for 1.3 as well
I think you are wrong again :)
I think you are wrong again :)
If you are using 1.4 there are a few new properties that you can use to set the timeout on a URLConnection.
The properties you need are sun.net.client.defaultConn
>>
It's not necessary to have 1.4. to do this. At least, it can be done quite effectively in 1.3.