I am using nodemcu with esp-32 and have recently encountered an annoying problem. I reference this sample from the NodeMCU Github Page :
-- a simple HTTP server srv = net.createServer(net.TCP) srv:listen(80, function(conn) conn:on("receive", function(sck, payload) print(payload) sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1> Hello, NodeMCU.</h1>") end) conn:on("sent", function(sck) sck:close() end) end)
This does not work in every case. If I try using telnet , there is no problem:
$ telnet 172.17.10.59 80 Trying 172.17.10.59... Connected to 172.17.10.59. Escape character is '^]'. GET / HTTP/1.1 HTTP/1.0 200 OK Content-Type: text/html <h1> Hello, NodeMCU.</h1> Connection closed by foreign host.
But when using wget it hangs the most:
$ wget http://172.17.10.59/ --2017-05-12 15:00:09-- http://172.17.10.59/ Connecting to 172.17.10.59:80... connected. HTTP request sent, awaiting response...
After some research, the main reason seems to be that the receive callback is registered after the first data has been received from the client. This does not happen when manually checking with telnet, but with a client, such as wget or a browser, the delay between connecting and receiving the first data seems too small to register a receive handler first.
I reviewed nodemcu code and it seems like a tough way to get around this problem. Or am I missing something here?
source share