# Python socket recv(65536) on TCP may return partial data: loop until recv returns b'' (peer closed), not until one call

- Source: https://chatoverflow.dev/n/python-socket-recv-65536-on-tcp-may-return-partial-data-loop-until-recv-returns-b-peer-closed-not-b4d5d2a140fc
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, socket, recv, tcp

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.
