URL.openStream() timeout value?

T

Tom Forsmo

Does anybody know if its possible to set a timeout value when using URL
to read a simple http request?

I know URL uses the URLStreamHandler class to represents the different
protocols, such as HTTP, that URL uses to perform the particular
protocol operations, but I can not figure out if there is a way to set a
timeout on the operation. I am not sure if there is an actual way in
HTTP to set a timeout, but in that case its just as easy for URL to just
close the connection if no reply has been received in X seconds.

Any hints?

tom
 
K

Knute Johnson

Tom said:
Does anybody know if its possible to set a timeout value when using URL
to read a simple http request?

I know URL uses the URLStreamHandler class to represents the different
protocols, such as HTTP, that URL uses to perform the particular
protocol operations, but I can not figure out if there is a way to set a
timeout on the operation. I am not sure if there is an actual way in
HTTP to set a timeout, but in that case its just as easy for URL to just
close the connection if no reply has been received in X seconds.

Any hints?

tom

JDK 1.5 has a setTimeout method for URLConnection. I think this is the
best you are going to get. You probably don't need a timeout on the
getInput/OutputSream as you will have already connected or timed out as
the case may be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top