Python uses Xmlrpc instances to explain

Source: Internet
Author: User
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))
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.