返回顶部

收藏

python xmlrpc实现文件传输的代码

更多

服务器端```python 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()

客户端代码```python
import xmlrpclib

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

标签:python

收藏

0人收藏

支持

0

反对

0

发表评论