我使用ftpsockets在python中创建一个文件服务器,其中多个客户机将图像发送到一个服务器。这是我用来在服务器端接收图像的方法:
while True:
data = client.recv(512)
if not data:
break
file.write(data)
这是我用来将图像发送到服务器的方法:
^{pr2}$我遇到的问题是,在服务器端while循环从未退出,这意味着代码要么卡在recv调用中,要么if语句永远不为true。在客户端没有问题,循环被正确退出。我听说客户端会向服务器发送一些东西,让它停止,但是if语句似乎没有接收到它。如何让服务器在不关闭连接的情况下停止尝试接收?在
https://docs.python.org/2/howto/sockets.html#disconnecting
在客户端上,关闭服务器的套接字。在服务器上,检查recv是否返回0字节。在
同样来自documentation for using a socket:
相关问题 更多 >
编程相关推荐