socket bindings

Charles G Waldman cgw at fnal.gov
Tue Jun 15 15:53:43 EDT 1999


Nathan Clegg writes:
 >> ... if I start the application again, it will die, saying
 >> the address is already bound to.

You need to specify the REUSEADDR flag on the socket, like this:

import socket
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind(host,port)



See the Unix manual pages or any decent network programming book for
more info on setsockopt.




More information about the Python-list mailing list