From e8d5a05952af9224d4b25036ae80e01eb5388095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Thu, 9 Mar 2017 22:19:18 +0100 Subject: [PATCH] Document that the socket receive event is fired for every frame, fixes #1849 --- docs/en/modules/net.md | 16 ++++++++++++++++ docs/en/modules/tls.md | 2 ++ 2 files changed, 18 insertions(+) diff --git a/docs/en/modules/net.md b/docs/en/modules/net.md index ec95d6bd..69a9ac09 100644 --- a/docs/en/modules/net.md +++ b/docs/en/modules/net.md @@ -324,6 +324,22 @@ srv:on("connection", function(sck, c) end) srv:connect(80,"httpbin.org") ``` +!!! note + The `receive` event is fired for every network frame! Hence, if the data sent to the device exceeds 1460 bytes (derived from [Ethernet frame size](https://en.wikipedia.org/wiki/Ethernet_frame)) it will fire more than once. There may be other situations where incoming data is split across multiple frames (e.g. HTTP POST with `multipart/form-data`). You need to manually buffer the data and find means to determine if all data was received. + +```lua +local buffer = nil + +srv:on("receive", function(sck, c) + if buffer == nil then + buffer = c + else + buffer = buffer .. c + end +end) +-- throttling could be implemented using socket:hold() +-- example: https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_examples/pcm/play_network.lua#L83 +``` #### See also - [`net.createServer()`](#netcreateserver) diff --git a/docs/en/modules/tls.md b/docs/en/modules/tls.md index 814bba82..3d28d1b3 100644 --- a/docs/en/modules/tls.md +++ b/docs/en/modules/tls.md @@ -148,6 +148,8 @@ srv:on("connection", function(sck, c) end) srv:connect(443,"google.com") ``` +!!! note + The `receive` event is fired for every network frame! See details at [net.socket:on()](net.md#netsocketon). #### See also - [`tls.createConnection()`](#tlscreateconnection)