obtain client ip address from SimpleXMLRPCServer ?

stuff at mailzilla.net stuff at mailzilla.net
Sun Jan 29 17:23:47 EST 2006


Thanks again Peter.  I found 2 potential solutions for obtaining the ip
address of the incoming
connection.  The first was to subclass SimpleXMLRPCRequestHandler class
and pass it
to the SimpleXMLRPCServer constructor.  In doing so, I could directly
access the client_address via self.client_address.  This worked just
fine but was a bit overkill.

The other solution I noticed was that SimpleXMLRPCServer's (which
ultimately subclasses BaseServer) handle_request method invokes
get_request (which merely calls self.socket.accept() -- which returns a
tuple including the ip address).  By re-implementing get_request() as
such:

def get_request(self):
    req = self.socket.accept()
    ip_address = req[1][0]
    return req

I can grab the ip address for internal use and have the get_request
method return the expected data for use by hande_request().

Now I just need to find a thread-safe way of passing this data back to
the XMLRPC server's registered_instance.




More information about the Python-list mailing list