RPC is the abbreviation of remote Procedure call, translated into Chinese is a long-distance method calls, is a local machine on the remote machine to invoke a process (method) technology, this process is called "distributed computing", is to improve the "interoperability" of each discrete machine and invented the technology.
The full name of XML-RPC is XML remote Procedure call, which is the XML remoting method invocation.
It is a set of specifications and a series of implementations that allow programs that run on different operating systems, in different environments, to implement Internet-based process calls.
This remote procedure call uses HTTP as the transport protocol, and XML as the encoding format for transmitting information.
The definition of XML-RPC is as simple as possible, but simultaneously capable of transmitting, processing, and returning complex data structures.
Xml-rpc under Python:
1, Class Library: Xmlrpclib is generally used in the client, this module is used to invoke the function registered on the XML-RPC server side, Xmlrpclib is not a type-safe module, unable to protect against maliciously constructed data, some processing work needs to be handed to the developer himself.
2, Class Library: Simplexmlrpcserver is generally used on the server side, this module is used to construct a most basic XML-RPC server framework
3. Construct a basic XML-RPC Server:
Copy the Code code as follows:
From Simplexmlrpcserver import Simplexmlrpcserver
def is_even (n):
return n%2 = = 0
Server = Simplexmlrpcserver (("localhost", 8000)) #确定URL和端口
Print "Listening on port 8000 ..."
Server.register_function (Is_even, "Is_even") #注册is_even函数
Server.serve_forever () #启动服务器 and make it available for this connection
4. Construct a basic XML-RPC Client:
Copy the Code code as follows:
Import Xmlrpclib
Proxy = Xmlrpclib. Serverproxy ("Http://localhost:8000/")
Print "3 is even:%s"% str (Proxy.is_even (3)) #客户端调用XML-rpc function
Print "Even:%s"% str (proxy.is_even (100))