Why not have a recvall method?
陶青云
qingyun.tao at tophant.com
Sun Feb 4 20:23:54 EST 2018
Thank you, it's very helpful.
I think the recvall should builtin to the _socket module like sendall.
------------------ Original ------------------
From: "Dan Stromberg"<drsalists at gmail.com>;
Date: Mon, Feb 5, 2018 06:01 AM
To: "陶青云"<qingyun.tao at tophant.com>;
Cc: "python-list"<python-list at python.org>;
Subject: Re: Why not have a recvall method?
On Sun, Feb 4, 2018 at 5:26 AM, 陶青云 <qingyun.tao at tophant.com> wrote:
> Hello, all
> The socket object has a `sendall` method that can send all bytes you specified.
> Oppositely, socket only has a recv method. I wonder why there is not a `recvall` method?
> To workaround this, I use `f = socket.makefile('rb')`, then all `f.read(n)`
> Thanks.
You're probably good with socket.makefile('rb').
An alternative that allows things like reading null-terminated input:
http://stromberg.dnsalias.org/~strombrg/bufsock.html
I wrote it and have been using it in production for years.
More information about the Python-list
mailing list