Article View: borland.public.jbuilder.java.api
Article #22Re: What the default timeout when new Socket()?
From: Shankar Unni
Date: Sun, 19 Dec 2004 18:57
Date: Sun, 19 Dec 2004 18:57
32 lines
2634 bytes
2634 bytes
Chris Wahl wrote:
> According to Javadoc, it is 0, ie, no timeout,
> but my progie really throw Exception:
> java.net.ConnectException: Connection timed out: connect
What that's saying is that it won't return a Java-library-imposed
timeout. You are still subject to the underlying networking layer's
timeouts *or errors*.
The timeouts can come for a variety of reasons:
* The address is invalid. This one should throw an exception right away,
but could be subject to DNS timeouts, especially if your DNS is
misconfigured.
* The address is correct, but there is no service listening on that
port. This will usually error out right away (with perhaps a small wait).
* The address is correct, and there is a service there, but it's hung or
busy (or otherwise not accept()ing your connection). This is where the
network-imposed connect timeout comes in.
* There is a firewall in between that is rejecting you, but is just
dropping the packets into the Great Bit Bucket In The Sky (the usual
behavior of firewalls, for good reason). This is subject to the TCP
layer timeouts.
The "Socket("host", port)" constructor is basically shorthand for
Socket s = new Socket();
s.connect("host", port); // the "0"-timeout variant.
If you call s.connect("host", port, timeout), then the call will time
out after the *earlier* of your timeout and the OS layer-imposed timeout
or error.
Technical Details
Message-ID:
<41c5cf24$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<41c5b550$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1089d0,b6c356190620dff9 X-Google-Attributes: gid1089d0,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Sun, 19 Dec 2004 10:57:40 -0800 From: Shankar Unni <shankarunni@netscape.net> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041201 Thunderbird/1.0RC1 Mnenhy/0.7 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.api Subject: Re: What the default timeout when new Socket()? References: <41c5b550$1@newsgroups.borland.com> In-Reply-To: <41c5b550$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 68.122.42.247 Message-ID: <41c5cf24$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1103482660 68.122.42.247 (19 Dec 2004 10:57:40 -0800) Lines: 32 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail