Python USES an XMLRPC instance to illustrate
- 2020-04-02 13:18:04
- OfStack
RPC, short for Remote Procedure Call, is a technique for calling a Procedure (method) on a Remote machine on a local machine. It is also known as "distributed computing" and was invented to improve the "interoperability" of separate machines.
The full name for xml-rpc is XML Remote Procedure Call, or XML Remote method Call.
It is a set of specifications and a series of implementations that allow programs running on different operating systems and environments to implement internet-based procedure calls.
This remote procedure call USES HTTP as the transport protocol and XML as the encoded format for transmitting information.
The definition of xml-rpc is as simple as possible, but at the same time capable of transmitting, processing, and returning complex data structures.
Xml-rpc in Python:
1. Class library: xmlrpclib Typically used on the client side, this module is used to call functions registered on the xml-rpc server side. Xmlrpclib is not a type-safe module that can resist malicious data construction, and some of this work needs to be left to the developers themselves.
2, library: SimpleXMLRPCServer Typically used on the server side, this module is used to construct a basic xml-rpc server framework
3. Construct a basic xml-rpc Server:
from SimpleXMLRPCServer import SimpleXMLRPCServer
def is_even(n):
return n%2 == 0
server = SimpleXMLRPCServer(("localhost", 8000))# determine URL And port
print "Listening on port 8000..."
server.register_function(is_even, "is_even") # registered is_even function
server.serve_forever()# Start the server , And make it available to this connection
4. Construct a basic xml-rpc Client:
import xmlrpclib
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
print "3 is even: %s" % str(proxy.is_even(3))# Client side call XML-RPC function
print "100 is even: %s" % str(proxy.is_even(100))