From: Raghuram D. <dra...@gm...> - 2007-08-14 03:56:25
|
On 8/13/07, bob...@ai... <bob...@ai...> 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 |