how to get any available port

Paul Rubin http
Tue Oct 4 23:26:16 CEST 2005

Mohammed Smadi <smadim2 at> writes:
> #transmission socket
> s = socket.socket(socket.AF_INET,  socket.SOCK_STREAM)
> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> s.bind(("",hp_port)) # do some error checking
> ...
> any suggestions for alternative implementation?

In this particular instance, don't bind the transmission socket.  I'm
also not sure why you set SO_REUSEADDR.  I've done some socket
programming but am no expert.

More information about the Python-list mailing list