Python Rebinding A Socket

For socket, use:

import socket

sock = socket.socket()  
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)  
sock.bind(('', 5555))  
sock.close()  

For socketserver, use:

import socketserver

socketserver.TCPServer.allow_reuse_address = True  
... do stuff ...

Konpat Preechakul

Read more posts by this author.