Python 自带 RPC Demo
Python 自带 RPC Demo
Server.py:
- from SimpleXMLRPCServer import SimpleXMLRPCServer
- def fun_add(a,b):
- totle = a + b
- return totle
- if __name__ == '__main__':
- s = SimpleXMLRPCServer(('0.0.0.0', 8080)) #开启xmlrpcserver
- s.register_function(fun_add) #注册函数fun_add
- print "server is online..."
- s.serve_forever() #开启循环等待
Client.py:
- from xmlrpclib import ServerProxy #导入xmlrpclib的包
- s = ServerProxy("http://172.171.5.205:8080") #定义xmlrpc客户端
- print s.fun_add(2,3)