RPC is the abbreviation of remote Procedure call, translated into Chinese is a long-distance method invocation, is a local machine on the remote machine to invoke a process (method) of technology, this process is also known as "distributed Computing", is to improve the "interoperability" of discrete machines and invented the technology.
The full name of XML-RPC is the Procedure call, XML remote method invocation.
It is a set of specifications and a series of implementations that allow programs in different operating systems and environments to implement internet-based process calls.
This remote procedure call uses HTTP as the transport protocol, and XML is used 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 generally used in the client, this module is used to call registered in the XML-RPC server-side functions, xmlrpclib is not a type-safe module, can not resist the malicious construction of data, some of the processing work needs to be given to the developer themselves.
2, Class Library: Simplexmlrpcserver is generally used on the server side, this module is used to construct a basic XML-RPC server framework
3. Construct a basic XML-RPC Server:
Copy 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 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 ' is even:%s '% str (proxy.is_even (100))