1

According to the Apache documentation, the 2 timeouts used on their sockets are the following:

CoreConnectionPNames.SO_TIMEOUT='http.socket.timeout': defines the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets). A timeout value of zero is interpreted as an infinite timeout. This parameter expects a value of type java.lang.Integer. If this parameter is not set, read operations will not time out (infinite timeout).

CoreConnectionPNames.CONNECTION_TIMEOUT='http.connection.timeout': determines the timeout in milliseconds until a connection is established. A timeout value of zero is interpreted as an infinite timeout. This parameter expects a value of type java.lang.Integer. If this parameter is not set, connect operations will not time out (infinite timeout).

Suppose I set both to 5s. If I perform an HTTP GET request on a slow server, and the following happens: The connnection is done within 5s. (CONNECTION_TIMEOUT is not triggered) IP packets keep trickling say every 4s (SO_TIMEOUT is not triggered) However it could take minutes for my HTTP GET or PUT to effectively complete. Is there a way to set a timeout to my overall GET or PUT request so that I can notify the user and/or give up.

user1654757
  • 300
  • 1
  • 5
  • 14
  • You can set timeout in the instance of the `HttpGet` class and it will work only for 1 request. – vortexwolf May 02 '13 at 12:04
  • I have not found an obvious way to do this. Could you please describe it a bit more. – user1654757 May 02 '13 at 17:11
  • Here is an example that you can use these parameters for either DefaultHttpClient or GetMethod: http://stackoverflow.com/a/694009/427225. – vortexwolf May 02 '13 at 19:55
  • 1
    I understand how to set The Socket and connection timeout, but they don't work for my use case. If I have timeouts of 5s and IP packets come every 4 seconds, the request could take minutes to complete without any timeout at the HTTP level. I want to be able to notify the user that his connection is slow or just abort the request if not completed in a certain timeFrame. – user1654757 May 03 '13 at 09:31
  • 1
    I would just display a progress bar, users know themselves what connection speed they have. As to 'abort the request if not completed in a certain timeFrame' you can look at this answer http://stackoverflow.com/a/2275596/427225. – vortexwolf May 03 '13 at 09:42

0 Answers0