xml rpc サーバー モジュールで 2 つのクラスを作成し、両方のクラスのインスタンスを xml rpc サーバーに登録しようとしています。単独で登録されている場合は両方のインスタンスからメソッドを実行できますが、そのうちの 1 つだけを実行すると登録が取得され、もう一方がエラーをスローします。また、インスタンスを最後に登録したクラスのメソッドしか表示できません。いいえに制限があるのだろうかと思っていました。このようなものを読んだことを覚えているので、サーバーに登録できるインスタンスの数は、ドキュメントに記載されていませんか?
これは私のサーバーコードです -
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()
これは私のクライアントコードです -
xmlrpclib をインポート
try:
#s = xmlrpclib.ServerProxy(r'http://administrator:passw0rd@172.19.201.59: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