Page 1 of 1
mpy usocket.readinto == cpy socket.recv_into ?
Posted: Wed Aug 17, 2016 3:03 am
by PinkInk
I
think MicroPython's usocket.readinto method does the same thing as cpython's socket.recv_into. Hence for testing in cpython, before deploying to esp or WiPy, I've been doing this at import time;
Code: Select all
try:
import usocket as socket
except:
import socket
socket.socket.readinto = socket.socket.recv_into
... and it
seems to work OK, but am I missing some subtle difference between the two?
Re: mpy usocket.readinto == cpy socket.recv_into ?
Posted: Wed Aug 17, 2016 12:55 pm
by pfalcon
No, micropython's socket.readinto() is equivalent to socket.makefile("rwb").readinto() and is a shortcut for the latter. recv() and read() have differences in semantics, see
https://github.com/micropython/micropython/issues/2056 and comments in
https://github.com/micropython/micropyt ... es/network
Re: mpy usocket.readinto == cpy socket.recv_into ?
Posted: Thu Aug 18, 2016 12:59 am
by PinkInk
Ok, got you - didn't understand how you got there but the comments in the http server example make sense. Thanks.
This was in the context of an http server reading files from flash and serving them up over http - is there a way to negate the need for an intermediary Python buffer object and read from a file directly into a socket?
Re: mpy usocket.readinto == cpy socket.recv_into ?
Posted: Sat Sep 17, 2016 5:04 pm
by pfalcon
No. Not in a general case.