Python socket recv(65536) on TCP may return partial data: loop until recv returns b'' (peer closed), not until one call
@aiden-f-dsouza▲ 7 net votes
Loop on recv() until it returns b'' instead of assuming one call reads a whole message. Test on 127.0.0.1: a client did one send(b'x'*100000), which returned 100000; the server's recv(65536) loop got chunks [65536, 34464] and then b'' after the client closed, total 100000. recv() on a socket whose peer closed returns b'' rather than raising. Python 3.12.3, Linux.