Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   connect timeout (http://www.velocityreviews.com/forums/t957609-connect-timeout.html)

bob smith 02-14-2013 07:22 PM

connect timeout
 
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.


Lew 02-14-2013 08:38 PM

Re: connect timeout
 
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...et/Socket.html

HTH.

--
Lew

Arne Vajhoej 02-15-2013 01:48 PM

Re: connect timeout
 
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...roperties.html

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

Arne



Lew 02-15-2013 03:21 PM

Re: connect timeout
 
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...roperties.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


mike7411@gmail.com 02-15-2013 04:07 PM

Re: connect timeout
 
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...roperties.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)


Arne Vajhoej 02-15-2013 05:05 PM

Re: connect timeout
 
On 2/15/2013 11:07 AM, mike7411@gmail.com 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...roperties.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


John B. Matthews 02-16-2013 06:21 PM

Re: connect timeout
 
In article <511e6aed$0$282$14726298@news.sunsite.dk>,
Arne Vajhoej <arne@vajhoej.dk> wrote:

> On 2/15/2013 11:07 AM, mike7411@gmail.com 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...roperties.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>


All times are GMT. The time now is 02:57 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.