Is there a way to distinguish between connection timeout and socket timeout?

Apache HttpClient framework allows you to specify connection timeout and socket timeout, for example:

final HttpParams httpParams = new BasicHttpParams();
if (connectionTimeout > 0) {
    HttpConnectionParams.setConnectionTimeout(httpParams, connectionTimeout);
}
if (socketTimeout > 0) {
    HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
}
HttpClient client = new DefaultHttpClient(httpParams);

      

I would like to fine tune the connection timeouts. This question perfectly explains the difference between the settings, but does not provide help for debugging the exceptions it throws.

My question is, what kind of exception is thrown for each type of timeout? I have java.net.SocketTimeoutException

; is it from connection timeout or socket timeout? I suspect this is the latter, especially since the message says, "Time has passed." What exception will be thrown for the connection timeout? TimeoutException

? ConnectException

? Why not related between timeout settings and exceptions lifted in Apache Http Docs ?

Direct parent classes for SocketTimeoutException

: InterruptedIoException

and ; the former has only a subclass, but has many subclasses. Is there another link that covers all the exceptions that you can expect to get from an HttpClient method ? He only announces that he can throw , which is really very wide. IOException

SocketTimeoutException

IOException

execute

IOException

+3


source to share


1 answer


I have not gone through the relationship between classes in the Java API, but I think you need



  • java.net.ConnectException: Packet loss due to wrong network, network congestion, too many server requests, firewall.

  • java.net.SocketTimeoutException: A socket timeout is the time it takes for a server socket to open while data is sent back to the caller. It might even be a server that is still processing and writing data, but it is taking quite a long time and the client has just timed it to wait.

+2


source







All Articles