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栈类实例分析

本文实例讲述了python栈类。分享给大家供大家参考。具体如下: class Path: #a list used like a stack def __init__(sel...

详解python读取和输出到txt

详解python读取和输出到txt

读取txt的数据和把数据保存到txt中是经常要用到的,下面我就总结一下。 读txt文件 python常用的读取文件函数有三种read()、readline()、readlines()...

python元组的概念知识点

元组(tuple)与列表类似,但是元组是不可修改的 (immutable)。也就是说,元组一旦被创建就不可被修改了。操作符 (in、+、*)和内置函数(len、max、min)对于元组的...

python过滤字符串中不属于指定集合中字符的类实例

本文实例讲述了python过滤字符串中不属于指定集合中字符的类。分享给大家供大家参考。具体如下: # -*- coding: utf-8 -*- import sets class...

Python中条件选择和循环语句使用方法介绍

同C语言、Java一样,Python中也存在条件选择和循环语句,其风格和C语言、java的很类似,但是在写法和用法上还是有一些区别。今天就让我们一起来了解一下。 一.条件选择语句 Pyt...