Home > Backend Development > Python Tutorial > python基于xmlrpc实现二进制文件传输的方法

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-10 15:11:05
Original
1358 people have browsed it

本文实例讲述了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()

Copy after login

客户端代码:

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

Copy after login

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template