setsockopt, part II
Constantinos A. Kotsokalis
C.Kotsokalis at ece.ntua.gr
Mon May 31 07:42:33 EDT 1999
I thought others might be interested in this (+ I was asked by one
of the people that helped to let the others know if what he was
suggesting works -- it did!).
The problem _was_:
I had a ThreadingTCPServer which I binded and called setsockopt()
with the arguments SOL_SOCKET, SO_REUSEADDR, 1. I wanted to be able
to reboot my server without waiting for older (binded) sockets to
close first. It didn't work.
The solution _is_:
Sub-class ThreadingTCPServer in order to call setsockopt() right
before bind():
class MyTCPServer(SocketServer.ThreadingTCPServer):
def server_bind(self):
self.socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
self.socket.bind(self.server_address)
addr = '127.0.0.1', BIND_PORT
srv = MyTCPServer(addr, handle_con)
srv.serve_forever()
The above works great.
Thanks to the fellow python-ers that helped out!
Costas
--
Constantinos A. Kotsokalis || C.Kotsokalis at ece.ntua.gr
National Technical University of Athens - GREECE
Electrical and Computer Engineering Department
"Bus error -- driver executed."
More information about the Python-list
mailing list