On Wed, Feb 2, 2011 at 5:24 PM, Brian Hurt <[email protected]> wrote:
> This isn't the right venue for this question, but I'm not sure where else to
> ask, and I'm hoping that someone here might be able to help.  Basically,
> I've got a program that, for long involved reasons, creates lots of sockets
> (millions).  It's closing them (clojure macros for the win), so I'm not
> running out of descriptors, but after a while, creating new sockets start
> throwing java.net.ConnectException: Cannot assign requested address errors.
> This problem always starts at about the same period of time, and seems to go
> away after a while (I'm trying to quantify how long).  Note that these are
> client sockets, not server sockets.  The exception makes perfect sense for
> server sockets (someone else has already bound the port you're trying to
> bind), but not for client sockets.

A new client port number is assigned every time the client opens a TCP
connection, and there are only 65536 port numbers, so eventually you
will run out.  I'm not familiar with how much control Java gives you
over the underlying C socket API, but you can share client port
numbers between sockets, as long as you make sure that two connections
*to the same server port on the same IP address* don't share port
numbers.

-- 
GMail doesn't have rotating .sigs, but you can see mine at
http://www.ccil.org/~cowan/signatures

-- 
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en.

Reply via email to