Reputation: 2410
I create little SimpleXMLRPCServer for check ip of client.
I try this:
import xmlrpclib
from SimpleXMLRPCServer import SimpleXMLRPCServer
server = SimpleXMLRPCServer(("localhost", 8000))
def MyIp(): return "Your ip is: %s" % server.socket.getpeername()
server.register_function(MyIp)
server.serve_forever()
import xmlrpclib
se = xmlrpclib.Server("http://localhost:8000")
print se.MyIp()
xmlrpclib.Fault: :(107, 'Transport endpoint is not connected')">
How make client_address visible to all functions?
Upvotes: 2
Views: 777
Reputation: 882103
If you want for example to pass client_address
as the first argument to every function, you could subclass SimpleXMLRPCRequestHandler (pass your subclass as the handler when you instantiate SimpleXMLRPCServer) and override _dispatch
(to prepend self.client_address
to the params tuple and then delegate the rest to SimpleXMLRPCRequestHandler._dispatch
). If this approach is OK and you want to see code, just ask!
I'm not sure how you'd safely use anything but the function arguments to "make client_address
visible" -- there's no client_address
as a bare name, global or otherwise, there's just the self.client_address
of each instance of the request handler class (and hacks such as copying it to a global variables feel really yucky indeed -- and unsafe under threading, etc etc).
Upvotes: 3