I don't think a random port must be used.  The issue is whether a port the program chooses is already in use.  So I think we should just look for an open port (above 1024)  and then use it.  I'll consider your algorithm, but it looks like we still need a scheme to choose another port in the probably quite rare chance that someone else grabs that very port in the window that you pointed out.

 - Bob


-----Original Message-----
From: Raghuram Devarakonda <draghuram@gmail.com>
To: boblusebob@aim.com <boblusebob@aim.com>
Cc: ohumbel@gmail.com; jython-dev@lists.sourceforge.net; charlie.groves@gmail.com
Sent: Mon, 13 Aug 2007 10:56 pm
Subject: Re: [Jython-dev] Test SocketServer

On 8/13/07, boblusebob@aim.com <boblusebob@aim.com> wrote:

> Does anyone see a problem with replacing this with picking the starting
> port number using a random number between 10001 and 20000 and increasing by
> one? Is there an advantage to using the pid? That would help make this
> test more platform independent. I don't think the Python version runs on
> all Platforms currently.

If a random port must be used, you can use the following function to find one.

def find_free_tcp_port():
s = socket.socket()
s.bind(("localhost", 0))
s.listen(1)
port = s.getsockname()[1]
s.close()
# There is a window here when the port can be taken by some one else.
return port

Check Out the new free AIM(R) Mail -- Unlimited storage and industry-leading spam and email virus protection.