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-----一些函数

            

       

  • 相关阅读:
    Refined Architecture阶段
    大三下学期第三周总结
    信息领域热词分析的-质量属性战术-可用性战术
    Docker ------ Dockerfile初探
    Docker ------ Swarm 初探
    Docker ------ Compose 初探
    正则表达式
    CRNN模型
    Docker容器 ---- pycharm远程连接
    python tgz包安装
  • 原文地址:https://www.cnblogs.com/xiaoyoucai/p/6539052.html
Copyright © 2011-2022 走看看