Commit afd974c5 authored by Marcel Stör's avatar Marcel Stör
Browse files

Correct socket:send example, fixes #1303

parent 498cc52a
...@@ -304,18 +304,19 @@ srv:listen(80, function(conn) ...@@ -304,18 +304,19 @@ srv:listen(80, function(conn)
response[#response + 1] = "e.g. content read from a file" response[#response + 1] = "e.g. content read from a file"
-- sends and removes the first element from the 'response' table -- sends and removes the first element from the 'response' table
local function send() local function send(sk)
if #response > 0 if #response > 0
then sck:send(table.remove(response, 1)) then sk:send(table.remove(response, 1))
else else
sck:close() sk:close()
response = nil
end end
end end
-- triggers the send() function again once the first chunk of data was sent -- triggers the send() function again once the first chunk of data was sent
sck:on("sent", send) sck:on("sent", send)
send() send(sck)
end) end)
end) end)
``` ```
...@@ -326,8 +327,8 @@ sck:send(header, function() ...@@ -326,8 +327,8 @@ sck:send(header, function()
local data1 = "some large chunk of dynamically loaded data" local data1 = "some large chunk of dynamically loaded data"
sck:send(data1, function() sck:send(data1, function()
local data2 = "even more dynamically loaded data" local data2 = "even more dynamically loaded data"
sck:send(data2, function() sck:send(data2, function(sk)
sck:close() sk:close()
end) end)
end) end)
end) end)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment