I'm trying to create 2 classed in xml rpc server module and then registering the instances of the both the classes to xml rpc server. I'm able to run the methods from both the instances when registered alone , however when i run only on of them get register and the other one throws error. Also I'm only able to see the methods of class whose instance i've registered last. I was wondering is there is limation on the no. of instances i can register in server, as I remember reading something like this but I can't find mention in the documentation now?
This is my server code -
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
# Create server
server = SimpleXMLRPCServer(("localhost", 8000), requestHandler=RequestHandler)
server.register_introspection_functions()
# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(pow)
#server.register_instance(FileOperation)
server.register_instance(file)
# Register a function under a different name
def adder_function(x,y):
return x + y
server.register_function(adder_function, 'add')
# Register an instance; all the methods of the instance are
# published as XML-RPC methods (in this case, just 'div').
class MyFuncs:
def div(self, x, y):
return x // y
class MyFuncs2:
def modulus(self, x, y):
return x % y
server.register_instance(MyFuncs2())
server.register_instance(MyFuncs())
# Run the server's main loop
server.serve_forever()
This is my client code -
import xmlrpclib
try:
#s = xmlrpclib.ServerProxy(r'http://administrator:[email protected]:8000')
s = xmlrpclib.ServerProxy(r'http://localhost:8000')
print s.system.listMethods()
print s.pow(2,3) # Returns 2**3 = 8
print s.add(2,3) # Returns 5
print s.div(5,2) # Returns 5//2 = 2
print s.moduls(5,2)
except Exception,err:
print err
I have the same experience as you, it's not completely explicit in the doc, but only one instance can be registered.
You can still do something like: