我正在尝试将文件从服务器发送到客户端,但出现错误。请让我知道我在哪里做错了。
这是我的服务器代码:
if msg in data.keys():
print("Requested file exists", msg)
f=open(msg,"rb")
datam= f.read(1024)
while (datam):
if(s.send(datam)):
print "sending data"
datam = f.read(1024)
s.close()
f.close
else:
print("File Not found",msg)
print("File Not found",data.keys())
c.close() # Close the connection
其中 msg 包含文件存在的路径地址 c=client socket s=server socket 我想读取该文件并将其发送给客户端,但我收到此错误
Got connection from ('127.0.0.1', 42330)
('Requested file exists', '/home/beenish/Pictures/pew.txt')
Traceback (most recent call last):
File "server.py", line 41, in <module>
if(s.send(datam)):
socket.error: [Errno 32] Broken pipe
在客户端,我编写了这段代码来接收该文件
s.listen(15)
f = open('\home\beenish\pictures\lol.txt', 'wb')
data = s.recv(1024)
while(data):
f.write(data)
data=s.recv(1024)
f.close()
s.close # Close the socket when done
其中 s 是客户端套接字
在这里我得到这个错误
Traceback (most recent call last):
File "client.py", line 26, in <module>
s.listen(15)
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 22] Invalid argument