Python XML RPC服务器端和客户端实例
一、远程过程调用RPC XML-RPC is a Remote Procedure Call method that uses XML passed via HTTP as a transport. With it,a client can call methods with parameters on a remote server (the server is named by a URI) and get back structured data. This module supports writing XML-RPC client code; it handles all the details of translating between conformable Python objects and XML on the wire. 简单地,client可以调用server上提供的方法,然后得到执行的结果。类似与webservice。 推荐查看xmlprc的源文件:C:Python31Libxmlrpc 二、实例 1) Server 复制代码 代码如下: from xmlrpc.server import SimpleXMLRPCServer def div(x,y): server = SimpleXMLRPCServer(("localhost",8000)) 2)client 复制代码 代码如下: import xmlrpc.client s = xmlrpc.client.ServerProxy('http://localhost:8000') print(s.system.listMethods()) print(s.pow(2,3)) # Returns 28 3)result (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |