[Python-Dev] Questionable TCP server example

Andrea Griffini agriff at tin.it
Thu Apr 23 09:21:11 CEST 2015


It's not the first time someone is confused by the server example of

https://docs.python.org/3/library/socketserver.html

where the receiving side is not making a loop over recv.

Moreover the documentation contains a misleading description of what really
happens:

"The difference is that the readline() call in the second handler will call
recv() multiple times until it encounters a newline character, while the
single recv() call in the first handler will just return what has been sent
from the client in one sendall() call."

Unless I'm missing something there's no way to know client side when all
data sent by "sendall" has been received (TCP stream protocol doesn't have
message boundaries) and the `recv` based code doesn't handle neither
fragmentation nor clients that send more than 1024 bytes.

Am I missing something or that is indeed an example of how NOT to write a
socket-based server?

Andrea
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150423/dbaf9552/attachment.html>


More information about the Python-Dev mailing list