connect timeout

Discussion in 'Java' started by bob smith, Feb 14, 2013.

  1. bob smith

    bob smith Guest

    Is there any way to specify the connection timeout for a java.net.Socket?

    I might want something like this to throw a ConnectException within 10 seconds:

    Socket socket = new Socket(ip_address, 80);

    Thanks.
     
    bob smith, Feb 14, 2013
    #1
    1. Advertising

  2. bob smith

    Lew Guest

    Lew, Feb 14, 2013
    #2
    1. Advertising

  3. bob smith

    Arne Vajhoej Guest

    On 2/14/2013 2:22 PM, bob smith wrote:
    > Is there any way to specify the connection timeout for a java.net.Socket?
    >
    > I might want something like this to throw a ConnectException within 10 seconds:
    >
    > Socket socket = new Socket(ip_address, 80);


    http://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html

    explains how to change default connect and read timeout for SUN/Oracle
    implementation.

    Arne
     
    Arne Vajhoej, Feb 15, 2013
    #3
  4. bob smith

    Lew Guest

    Arne Vajhoej wrote:
    > bob smith wrote:
    >> Is there any way to specify the connection timeout for a java.net.Socket?

    >
    >> I might want something like this to throw a ConnectException within 10 seconds:

    >
    >> Socket socket = new Socket(ip_address, 80);

    >
    > http://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html
    >
    > explains how to change default connect and read timeout for SUN/Oracle
    > implementation.


    The two-lines-of-code approach doesn't require an exogenous declaration of
    the property, which is an advantage if you don't want to rely on the correct
    invocation of the program and a disadvantage if you want the same code to
    handle different configurations.

    --
    Lew
     
    Lew, Feb 15, 2013
    #4
  5. bob smith

    Guest

    On Friday, February 15, 2013 7:48:11 AM UTC-6, Arne Vajhoej wrote:
    > On 2/14/2013 2:22 PM, bob smith wrote:
    >
    > > Is there any way to specify the connection timeout for a java.net.Socket?

    >
    > >

    >
    > > I might want something like this to throw a ConnectException within 10 seconds:

    >
    > >

    >
    > > Socket socket = new Socket(ip_address, 80);

    >
    >
    >
    > http://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html
    >
    >
    >
    > explains how to change default connect and read timeout for SUN/Oracle
    >
    > implementation.
    >
    >
    >
    > Arne


    Thanks.

    BTW, do you know what that means that the default is -1?

    sun.net.client.defaultConnectTimeout (default: -1)
    sun.net.client.defaultReadTimeout (default: -1)
     
    , Feb 15, 2013
    #5
  6. bob smith

    Arne Vajhoej Guest

    On 2/15/2013 11:07 AM, wrote:
    > On Friday, February 15, 2013 7:48:11 AM UTC-6, Arne Vajhoej wrote:
    >> On 2/14/2013 2:22 PM, bob smith wrote:
    >>> Is there any way to specify the connection timeout for a java.net.Socket?
    >>> I might want something like this to throw a ConnectException within 10 seconds:
    >>> Socket socket = new Socket(ip_address, 80);

    >> http://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html
    >> explains how to change default connect and read timeout for SUN/Oracle
    >> implementation.

    > BTW, do you know what that means that the default is -1?
    >
    > sun.net.client.defaultConnectTimeout (default: -1)
    > sun.net.client.defaultReadTimeout (default: -1)


    I assume -1 means not set.

    Arne
     
    Arne Vajhoej, Feb 15, 2013
    #6
  7. In article <511e6aed$0$282$>,
    Arne Vajhoej <> wrote:

    > On 2/15/2013 11:07 AM, wrote:
    > > On Friday, February 15, 2013 7:48:11 AM UTC-6, Arne Vajhoej wrote:
    > >> On 2/14/2013 2:22 PM, bob smith wrote:
    > >>> Is there any way to specify the connection timeout for a
    > >>> java.net.Socket? I might want something like this to throw a
    > >>> ConnectException within 10 seconds:
    > >>> Socket socket = new Socket(ip_address, 80);
    > >> http://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html
    > >> explains how to change default connect and read timeout for
    > >> SUN/Oracle implementation.

    > > BTW, do you know what that means that the default is -1?
    > >
    > > sun.net.client.defaultConnectTimeout (default: -1)
    > > sun.net.client.defaultReadTimeout (default: -1)

    >
    > I assume -1 means not set.


    This would comport with how -1 is used elsewhere in the cited document
    to mean "forever," perhaps in the sense of "no specified timeout."

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
     
    John B. Matthews, Feb 16, 2013
    #7
    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. Otis Mukinfus
    Replies:
    3
    Views:
    925
    Juan T. Llibre
    Jul 8, 2005
  2. Replies:
    3
    Views:
    40,300
    Roedy Green
    Nov 16, 2005
  3. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,296
    Brian Candler
    Oct 6, 2004
  4. Replies:
    2
    Views:
    289
  5. Mohsen Pahlevanzadeh

    Qt connect and first connect or unicode

    Mohsen Pahlevanzadeh, Sep 17, 2013, in forum: Python
    Replies:
    3
    Views:
    155
    Mohsen Pahlevanzadeh
    Sep 18, 2013
Loading...

Share This Page