我是套接字编程和python的初学者。我想学习如何从服务器向客户端发送一个大文本文件(例如,> 5MB)。我不断收到一条错误消息
Traceback (most recent call last):
File "fserver.py", line 50, in <module>
reply = f.read()
ValueError: Mixing iteration and read methods would lose data
以下是我的部分代码。有人可以看一下并给我一些有关如何解决此问题的提示吗?感谢您的时间。
我的服务器.py
#validate filename
if os.path.exists(filename):
with open(filename) as f:
for line in f:
reply = f.read()
client.send(reply)
#f = open(filename, 'r')
#reply = f.read()
#client.send(piece)
else:
reply = 'File not found'
client.send(reply)
我的客户端.py
while True:
print 'Enter a command: list or get <filename>'
command = raw_input()
if command.strip() == 'quit':
break
client_socket.send(command)
data = client_socket.recv(socksize)
print data