find_free_port at [d45c5b5e45]
Not logged in

File find_free_port artifact 6153a27ecd part of check-in d45c5b5e45


#!/usr/bin/python
import sys,socket,errno
if len(sys.argv)>1:
	port=int(sys.argv[1])
else:
	port=5900
    
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while True:
    try:
        s.bind(("",port))
    except socket.error as e:
        if e.errno== errno.EADDRINUSE:
            port+=1
            continue
        else:
            raise e
    break

s.close()
print port