zoukankan      html  css  js  c++  java
  • 17.3.12---xmlrpclib模块

    1----XML-RPC是一种使用xml文本的方式利用http协议传输命令和数据的rpc基址,我们用pythom的想mlrpclib模块可以让程序与其他任何语言编写的XML-RPC服务器进行数据传输

       

      首先,我们用Python写一个简单的8080端口服务器,源码如下:

    # sxr.py 新建文件,名字为sxr.py

    from SimpleXMLRPCServer import SimpleXMLRPCServer

    def happy():
        print "I play Python.!"
        sxr=SimpleXMLRPCServer(("", 8080), allow_none=True)
        sxr.register_function(happy)
        sxr.serve_forever()

    然后,我们运行程序,启动SimpleXMLRPCServer模块的服务器。

    $ : python sxr.py # 启动sxr.py服务器文件,也就是上面的代码。

    最后,使用xmlrpclib模块ServerProxy方法连接至上面的服务器,看下面代码:

    #happy.py 再次新建一个文件,名为 happy.py

    from xmlrpclib import ServerProxy

    sp = ServerProxy("http://localhost:8080")
    sp.happy()

    启动,并运行,看到终端模拟器或者Windows的Dos界面中,输出 “I play Python.”,就证明我们已经和xml-rpc服务器连接上了。

    2-----一些函数

            

       

  • 相关阅读:
    pytest框架运用
    unitTest学习
    发送邮件
    python 连接远程服务器,修改时间
    Redis基础
    django 知识点扩展
    ACM 题目 1487: [蓝桥杯][算法提高VIP]不同单词个数统计
    Leetcode 面试题 08.01. 三步问题
    Leetocode 198. 打家劫舍
    Leetcode 121. 买卖股票的最佳时机
  • 原文地址:https://www.cnblogs.com/xiaoyoucai/p/6539052.html
Copyright © 2011-2022 走看看