On 12/27/06, Tim Ellison <t.p.ellison@gmail.com> wrote:
>
> Mikhail Markov wrote:
> > Why not use ServerSocket(0) to just *obtain* some positive non-busy port
> > number (and close it after port number obtaining) and after that test
> > ServerSocket constructor with this obtained port number? In this case
> we'll
> > not require any reserved ports at all.
>
> There is obviously a race condition there, so you may have to make a
> number of attempts to get the port you think is now free before others
> take it.
The only race condition i see here is that another process could take this
port between closing of 1-st ServerSocket and opening a new one.
Is this what you mean?
(But the same thing may happen if one of applications takes pre-defined
fixed port at any point during tests run when it's free.)
Regards,
Mikhail
Regards,
> Tim
>
|