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

Discussion in 'Java' started by billdavidcn@gmail.com, May 22, 2007.

  1. Guest

    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?
     
    , May 22, 2007
    #1
    1. Advertising

  2. SadRed Guest

    On May 22, 12:10 pm, 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?
     
    SadRed, May 22, 2007
    #2
    1. Advertising

  3. Guest

    Thanks.
    I have made a mistake, I have not handled the right exception, the
    exception should be SocketTimeoutException.
     
    , May 22, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Niels Campbell

    HttpURLConnection timeout solution

    Niels Campbell, Jan 23, 2004, in forum: Java
    Replies:
    6
    Views:
    44,077
    dadada
    Oct 27, 2006
  2. SPG
    Replies:
    1
    Views:
    711
  3. \A_Michigan_User\
    Replies:
    2
    Views:
    938
    \A_Michigan_User\
    Aug 21, 2006
  4. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    5,415
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
  5. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,351
    Brian Candler
    Oct 6, 2004
Loading...

Share This Page