Python socket.send() can only send once, then socket.error: [Errno 32] Broken pipe occurred

强颜欢笑 提交于 2019-12-02 23:40:18

handle() is called in the SocketServer.StreamRequestHandler once for each connection. If you return from handle the connection is closed.

If you want the server to handle more than one send/recv, you must loop until recv() returns 0, indicating the client closed the connection (or at least called shutdown() on sends).

Also note that TCP is a streaming protocol. You'll need to design a message protocol that indicates the length or end of a message, and buffer recv until you have a complete message. Check send return value to make sure all the message is sent as well, or use sendall.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!