Let the OS select an unused port instead of using a random integer.

This patch replaces the randint() call (for selecting a port number) with the 'port 0 trick' to make the OS select a free port, avoiding port-number collisions.

randint(1025, 65535) is nice and quick, but it's annoying if it returns a port that's already in use.