function handleHttpRequest(client, request)
...
end
function setupHttpServer()
srv = net.createServer(net.TCP);
srv:listen(80, function(conn)
conn:on("receive", handleHttpRequest);
end);
end
I do understand asynchronous API's, but TCPIP is in essence a streaming API. So, I'm confused about the data that the callback e.g. handleHttpRequest gives me. How much of the data that is on the socket is being offered in the call back ? If the data does not fit in the buffer(s), then what is happening with the rest of the data on the socket ?
E.g., the 1460 byte buffer did get filled completely by Windows 10 trying to connect to my AP. Windows 10 does send a GET request with about 4000 bytes of data in cookies. I noticed that the data given to me in the callback function was just a part of this. The callback was called about 3 times in a row, each time with a part of the data.
I'm not sure how - as a developer - I need to deal with that. How do I know which data belongs together ? And - even if I would would path the buffer length - TCPIP is a streaming protocol that delivers data in chunks. So, I would expect the data to be delivered in pieces from time to time.
Using a more classical API, I did solve this by blocking receive calls on the socket, or - in case a Lua - to yield from a coroutine until more data is available. Is something similar possible in nodemcu ? If not, then how am I to deal with receiving data over a socket in the 'correct' way ?