Oleg, I guess even Windows provides an API function that allocates a free local port automatically. I don't think that Java handles the allocation of the local port number in any way.

Odi

Oleg Kalnichevski wrote:
Alex,

This is just a guess on my part, so take it for what it is worth. The
JVM randomly assigns a local port for an outbound connection, if the
port has not been explicitly given. I assume most JVMs make no
provisions to ensure that under no circumstances the same number gets
assigned more than once. When under heavy load it is perfectly feasible
that, while a connection is being established, the same number gets assigned to another connection, thus causing BindException.


Consider the following options:

(1) reuse connections as much as possible to minimize odds of having to
open new sockets
(2) implement your own algorithm to assign local ports
(3) simply retry Socket#bind method in case of BindException

Hope this helps

Oleg

--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to