Python uses Xmlrpc instance to explain _python

Source: Internet
Author: User
Tags data structures

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))

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.