XMLRPCServer / Python

Useful trick on Linux when you need to reconnect often to the same socket.

import SocketServer
import SimpleXMLRPCServer        

class MyTCPServer(SocketServer.TCPServer):
    def server_bind(self):
        self.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
        self.socket.bind(self.server_address)

class MyXMLRPCServer(MyTCPServer, SimpleXMLRPCServer.SimpleXMLRPCDispatcher):
    def __init__(self, addr, requestHandler=SimpleXMLRPCServer.SimpleXMLRPCRequestHandler, logRequests=1):
        self.logRequests = logRequests
        SimpleXMLRPCServer.SimpleXMLRPCDispatcher.__init__(self)
        MyTCPServer.__init__(self, addr, requestHandler)

my_object = MyObject()
server = MyXMLRPCServer(("localhost", 8000),logRequests=False)
server.register_instance(self.my_object)        
while True:
    self.server.handle_request()