【发布时间】:2020-04-20 13:44:28
【问题描述】:
当我尝试从服务器获取文件时,我得到的第一个文件没有问题,而不是第二个文件出现此错误; OSError: [WinError 10056] 在已连接的套接字上发出了连接请求
客户端.py
files={
"file1":"10.10.10.10",
"files2":"10.10.10.15"
}
json={
"filename" : ""
}
while 1:
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
for file,ip in files:
json["filename"] = file
requestJSON = json.dumps(json)
socket.connect((ip, 3875))
socket.send(bytes(requestJSON, encoding='utf-8'))
with open("loc/" + file, 'w') as f:
while True:
print('receiving data...')
data = socket.recv(1024)
if not data:
break
f.write(data)
f.close()
socket.close()
服务器.py
while 1:
conn, addr = socket.accept()
msg=conn.recv(1024)
file=json.loads(msg.decode('utf-8'))
fp = "/loc/" + file["filename"]
f = open(fp, 'rb')
d = f.read(1024)
while d:
clientSock.send(d)
l = f.read(1024)
f.close()
【问题讨论】:
标签: python sockets python-sockets