python基于xmlrpc實現二進制文件傳輸的方法
更新時間:2015年06月02日 16:16:52 作者:songguo
這篇文章主要介紹了python基于xmlrpc實現二進制文件傳輸的方法,實例分析了xmlrpclib模塊的使用技巧,需要的朋友可以參考下
本文實例講述了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 中的 type(), dtype(), astype()的區(qū)別
這篇文章主要介紹了淺談python 中的 type(), dtype(), astype()的區(qū)別,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04

