Message from discussion
Socket woes
Path: g2news1.google.com!news1.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!news.compaq.com!newsfeed1.sea.pnap.net!newsfeed2.sea.pnap.net!newsfeed.pnap.net!brmea-news-1.sun.com!news1brm.central.sun.com!not-for-mail
From: Eric Sosman <eric.sos...@sun.com>
Newsgroups: comp.lang.java.help
Subject: Re: Socket woes
Date: Wed, 30 Mar 2005 17:20:49 -0500
Organization: Sun Microsystems Corporation
Lines: 34
Message-ID: <d2f8o1$d6m$1@news1brm.Central.Sun.COM>
References: <d2f6d6$b8d$1@gondor.sdsu.edu>
NNTP-Posting-Host: tardis.east.sun.com
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: news1brm.Central.Sun.COM 1112221250 13526 129.148.168.113 (30 Mar 2005 22:20:50 GMT)
X-Complaints-To: usenet@news1brm.central.sun.com
NNTP-Posting-Date: Wed, 30 Mar 2005 22:20:50 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.4) Gecko/20041214
X-Accept-Language: en-us, en
In-Reply-To: <d2f6d6$b8d$1@gondor.sdsu.edu>
David F wrote:
> Howdy -
>
> I have a client program that throws the following exception:
> Address already in use: connect
> java.net.BindException: Address already in use: connect
>
> This client rapidly creates socket connections in a loop for stress
> testing the server. The server works great! :) I didn't expect
> the client to break tho. The last test I did, the client looped
> about 4200 times on the first run, 810 times when run a few seconds
> later, then about 4200 times after waiting a few minutes.
>
> I suspect it's a garbage collection problem. Could my program be
> consuming sockets faster than the garbage collector cleans them
> up?
It seems more likely that you're consuming port numbers
faster than TCP/IP can recycle them. After a socket is
closed the port number remains unavailable for a time (four
minutes "by statute," IIRC, although it's fairly common for
Web servers to use shorter intervals); this is to allow time
for stale packets to expire from the network. (You wouldn't
want a packet that had been temporarily trapped in a routing
loop to escape and disrupt a new unrelated connection that
happened to use the same port number ...)
See java.net.Socket#setReuseAddress(boolean).
--
Eric.Sos...@sun.com