When using java.net.Socket.connect()
, both a refused connection and a timeout result in a ConnectException
.
java.net.ConnectException: Connection timed out: connect
java.net.ConnectException: Connection refused: connect
How can I safely distinguish between the two? Sure parsing the error message does the job. But when the message changes in a future Java release, I'm out of luck.
The bigger picture: I'm writing a web service client using JAX-WS with a Metro implementation. When a web service call fails, I want to report the reason for the failure clearly so the issue can be resolved quickly.
In general, connection refused errors are generated during a connect system call when an application attempts to connect using TCP to a server port which is not open.
The connection timeout is the timeout in making the initial connection; i.e. completing the TCP connection handshake. The read timeout is the timeout on waiting to read data1.
request timeout — a time period required to process an HTTP call: from sending a request to receiving a response. connection timeout — a time period in which a client should establish a connection with a server.
A server connection timeout means that a server is taking too long to reply to a data request made from another device. Timeouts are not a reply message: they show up when there isn't a reply and a server request is not fulfilled in a predetermined length of time.
Measure the time passed between invoking connect() and the exception was thrown, and pass that information on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With