python基于xmlrpc实现二进制文件传输的方法

yipeiwu_com6年前Python基础

本文实例讲述了python基于xmlrpc实现二进制文件传输的方法。分享给大家供大家参考。具体实现方法如下:

服务器端:

from SimpleXMLRPCServer import SimpleXMLRPCServer
import xmlrpclib
def python_logo():
   handle = open("python_logo.jpg",'rb')
   return xmlrpclib.Binary(handle.read())
   handle.close()
server = SimpleXMLRPCServer(("localhost", 8000))
print "Listening on port 8000..."
server.register_function(python_logo, 'python_logo')
server.serve_forever()

客户端代码:

import xmlrpclib
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
handle = open("fetched_python_logo.jpg", "wb")
handle.write(proxy.python_logo().data)
handle.close()

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python MySQLdb使用教程详解

python MySQLdb使用教程详解

本文主要内容python MySQLdb数据库批量插入insert,更新update的: 1.python MySQLdb的使用,写了一个基类让其他的sqldb继承这样比较方便,数据库的...

django rest framework之请求与响应(详解)

前言:在上一篇文章,已经实现了访问指定URL就返回了指定的数据,这也体现了RESTful API的一个理念,每一个URL代表着一个资源。当然我们还知道RESTful API的另一个特性就...

Python 实现简单的shell sed替换功能(实例讲解)

code: f = open('yesterday','r',encoding='utf-8') f2 = open('yesterday.bak','w',encoding='ut...

使用Filter过滤python中的日志输出的实现方法

事情是这样的,我写了一个tornado的服务,过程当中我用logging记录一些内容,由于一开始并没有仔细观察tornado自已的日志管理,所以我就一般用debug来记录普通日志,err...

python实现输入的数据在地图上生成热力图效果

我就废话不多说了,直接贴代码,注意要先安装folium #-*-coding:utf8-*- #输入data生成热力图html,借助了leaflet,没网不能用 import o...