1, first say the conclusion: the use of XML-RPC mechanism can be very convenient to implement RPC calls between servers.
2. The test results are as follows:
3. The source code is as follows:
The source code for the server side is as follows:
Import operator, Mathfrom simplexmlrpcserver import simplexmlrpcserverfrom functools import reducedef Main (): Server = Simplexmlrpcserver ((' 127.0.0.1 ', 7001)) server.register_introspection_functions () Server.register_multicall_functions () server.register_function (addtogether) server.register_function ( Quadratic) server.register_function (REMOTE_REPR) print ("Server Ready") Server.serve_forever () def addtogether (*things): "" " Add together everything in the list things. " " return reduce (Operator.add, things) def quadratic (A, B, c): "" " determine x values satisfying:a * x * x + b * x + c = 0 "" " B24ac = math.sqrt (b*b-4.0*a*c) return list (set ([(-B-B24AC)/2.0*a, (-B+B24AC)/2.0*a]) def Remote_repr (ARG): "" " Return the repr () rendering of the supplied arg" "" return arg if __name__ = = ' __main_ _ ': Main ()
The code for the client is as follows:
Import Xmlrpclibdef Main (): Proxy = Xmlrpclib. Serverproxy (' http://127.0.0.1:7001 ') print ("Here is the functions supported by this server:") print ("Next C Alculator addtogether: ") Print (Proxy.addtogether (' x ', ' y ', ' z ')) print (Proxy.addtogether (' x ', ' y ', ' z ')) print (p Roxy.addtogether (' x ', ' y ', ' z ')) print (Proxy.addtogether (' x ', ' y ', ' z ')) for method_name in Proxy.system.listMethods (): If Method_name.startswith (' System. '): Continue signatures = Proxy.system.methodSigna Ture (method_name) if isinstance (signatures, list) and signatures:for signature in signatures: Print ('%s (%s) '% (method_name, signature)) Else:print ('%s (...) '% (Method_name,)) Method_help = Proxy.system.methodHelp (method_name) #if method_help: # Print (", method Help) Print (Proxy.addtogether (' x ', ' y ', ' z ')) print ("Addtogether result") If __name__ = = ' __main__ ': Main ()