Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to control the timeout of the whole session with HttpUrlConnection?

Reply
Thread Tools

How to control the timeout of the whole session with HttpUrlConnection?

 
 
billdavidcn@gmail.com
Guest
Posts: n/a
 
      05-22-2007
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?

 
Reply With Quote
 
 
 
 
SadRed
Guest
Posts: n/a
 
      05-22-2007
On May 22, 12:10 pm, (E-Mail Removed) wrote:
> 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?


> client doesn't close the session in 20s

Read would timeout and an exception would be thrown. What your client
were doing in that 20s?

 
Reply With Quote
 
 
 
 
billdavidcn@gmail.com
Guest
Posts: n/a
 
      05-22-2007
Thanks.
I have made a mistake, I have not handled the right exception, the
exception should be SocketTimeoutException.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Session Timeout problems-web.confg session state and IIS session s =?Utf-8?B?Um9iSEs=?= ASP .Net 4 04-11-2007 04:52 PM
*WITHOUT* using: ValidateRequest="False" for the whole page (or my whole site).... \A_Michigan_User\ ASP .Net 2 08-21-2006 02:13 PM
Timeout::timeout and Socket timeout Mark Probert Ruby 1 10-06-2004 09:30 AM
Session contents lost despite Session.Timeout = 3000; and <sessionState mode="InProc" cookieless="false" timeout="300"> Carpe Diem ASP .Net 3 02-23-2004 07:10 PM



Advertisments