B
billdavidcn
How to control the timeout of the whole session with
HttpUrlConnection?
I find the following fact during test:
HttpUrlConnection.setConnectTimeout can only control the timeout of
connect operation, while setReadTimeout can only control the timeout
of read.
I have done an experiment and set timeout value in the following way:
m_connection.setConnectTimeout(1000);
m_connection.setReadTimeout(20 * 1000);
And in server side, I add the following sentence to make it delay to
response:
Thread.sleep(60 * 1000);
The result shows, client doesn't close the session in 20s, and the
communication completes after 60s when server responses it at last.
How could I close the session in 20s? I think to add a Timer should be
a solution, but is there any better choice?
HttpUrlConnection?
I find the following fact during test:
HttpUrlConnection.setConnectTimeout can only control the timeout of
connect operation, while setReadTimeout can only control the timeout
of read.
I have done an experiment and set timeout value in the following way:
m_connection.setConnectTimeout(1000);
m_connection.setReadTimeout(20 * 1000);
And in server side, I add the following sentence to make it delay to
response:
Thread.sleep(60 * 1000);
The result shows, client doesn't close the session in 20s, and the
communication completes after 60s when server responses it at last.
How could I close the session in 20s? I think to add a Timer should be
a solution, but is there any better choice?