Re: Why not have a recvall method?
Thank you, it's very helpful. I think the recvall should builtin to the _socket module like sendall. -- Original -- From: "Dan Stromberg"; Date: Mon, Feb 5, 2018 06:01 AM To: "陶青云"; Cc: "python-list"; Subject: Re: Why not have a recvall method? On Sun, Feb 4, 2018 at 5:26 AM, 陶青云 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. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why not have a recvall method?
On Sun, Feb 4, 2018 at 5:26 AM, 陶青云 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. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why not have a recvall method?
makefile('rb') return a io.BufferedReader and the doc(https://docs.python.org/3/library/io.html#io.BufferedIOBase.read) says: If the argument is positive, and the underlying raw stream is not interactive, multiple raw reads may be issued to satisfy the byte count (unless EOF is reached first). -- Original -- From: "Steven D'Aprano"; Date: Sun, Feb 4, 2018 09:31 PM To: "python-list"; Subject: Re: Why not have a recvall method? On Sun, 04 Feb 2018 19:26:36 +0800, 陶青云 wrote: > Hello, allThe 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 `call f.read(n)` Thanks. I am not an expert on sockets, but since f.read(n) will read a maximum of n bytes, isn't that the same as socket_obj.recv(n)? -- Steve -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Why not have a recvall method?
On Sun, 04 Feb 2018 19:26:36 +0800, 陶青云 wrote: > Hello, allThe 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 `call f.read(n)` Thanks. I am not an expert on sockets, but since f.read(n) will read a maximum of n bytes, isn't that the same as socket_obj.recv(n)? -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Why not have a recvall method?
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. -- https://mail.python.org/mailman/listinfo/python-list
Why not have a recvall method?
Hello, allThe 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 `call f.read(n)` Thanks. -- https://mail.python.org/mailman/listinfo/python-list
recvall()
Hi All, I am trying to program an HTTP webserver, I am a little confused about the best way to program a recvall function. There are a couple of ways to do this? But performance wise which one is better? a) recvall using a timeout? b) recvall using a condition that nothing was received? c) recvall using a condition for it to wait for a CRLF or a timeout whichever occurs first? Any help would be appreciated. Regards, Nav -- http://mail.python.org/mailman/listinfo/python-list