From afd974c5e9b942cf1124c9498dc9588ba73679e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Sun, 22 May 2016 21:50:57 +0200 Subject: [PATCH] Correct socket:send example, fixes #1303 --- docs/en/modules/net.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/en/modules/net.md b/docs/en/modules/net.md index b5731ed8..fcd872c1 100644 --- a/docs/en/modules/net.md +++ b/docs/en/modules/net.md @@ -304,18 +304,19 @@ srv:listen(80, function(conn) response[#response + 1] = "e.g. content read from a file" -- sends and removes the first element from the 'response' table - local function send() + local function send(sk) if #response > 0 - then sck:send(table.remove(response, 1)) + then sk:send(table.remove(response, 1)) else - sck:close() + sk:close() + response = nil end end -- triggers the send() function again once the first chunk of data was sent sck:on("sent", send) - send() + send(sck) end) end) ``` @@ -326,8 +327,8 @@ sck:send(header, function() local data1 = "some large chunk of dynamically loaded data" sck:send(data1, function() local data2 = "even more dynamically loaded data" - sck:send(data2, function() - sck:close() + sck:send(data2, function(sk) + sk:close() end) end) end)