XMLRPCServer / Python

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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()