micropython / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
Other
19.22k stars 7.7k forks source link

ESP8266 socket.recv(1024) doesn't get all data #8430

Closed xboxplayer9889 closed 2 years ago

xboxplayer9889 commented 2 years ago

ESP8266 (ESP8266EX, ESP-12F, v1.18 (2022-01-17) .bin)

socket.recv() doesn't get all data on POST

with GET I can receive all the data, but with POST if the request size bigger than 536byte I receive the first 536, and no more come, repeated recv hangs/waits too much, no error, but page cannot be served.

similar closed issue, same code: https://github.com/micropython/micropython/issues/7605#issue-957470751

xboxplayer9889 commented 2 years ago

Although socket.recv() didn't work well for me, I have inspected this example and it helped me to rewrite my code to get any info (all the HEAD data with cookies, POST): https://github.com/micropython/micropython/blob/master/examples/network/http_server.py

dpgeorge commented 2 years ago

This is expected behaviour, socket.recv(n) reads at most n bytes from the stream, but maybe less. It will not block if there is at least one 1 byte to return.

I see you have found a way forward, so will close the issue.

xboxplayer9889 commented 2 years ago

Thanks for answering,

But I'm happy I have learnt more about HTTP packets and I think not recv(bigbuffer) is the good solution.... Ty