python 实现 RPC 通信

发布时间:2019-09-24 08:27:17编辑:auto阅读(2276)

    

    例子:

    Python RPC Server

    import SimpleXMLRPCServer

    class MyObject:
         def sayHello(self):
             return "hello ZQF, That is xmlprc Respond."

    obj = MyObject()
    server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 80))
    server.register_instance(obj)

    print "Listening on port 80"
    server.serve_forever()

    Python RPC Client

    import xmlrpclib

    server = xmlrpclib.ServerProxy("http://localhost:80")

    words = server.sayHello()

    print "result:" + words



关键字