From 4b1cea022424be9cd67ec559b545ef86c6e8174e Mon Sep 17 00:00:00 2001 From: C3MA Date: Sat, 17 Dec 2016 02:09:23 +0100 Subject: [PATCH] Further webserver stuff --- index.html | 8 +++++--- webserver.lua | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index b2bb521..a6caac6 100644 --- a/index.html +++ b/index.html @@ -15,6 +15,8 @@ 4. Minute Color" Three quaterDreiviertel Joa/nei ColorModeIf checked, words are dark, rest is colored -
" -
" -" \ No newline at end of file +
+
+ +$ADDITIONAL_LINE + \ No newline at end of file diff --git a/webserver.lua b/webserver.lua index 6211157..9c1971a 100644 --- a/webserver.lua +++ b/webserver.lua @@ -2,6 +2,42 @@ configFile="config.lua" +sentLines=0 +sendFile=nil +function sendPage(conn, nameOfFile) + if (sentLines > 0) then + print("There is a site already sent") + return + end + sendFile=nameOfFile + + if file.open(sendFile, "r") then + local line = file.readLine() + -- TODO replace the tokens in the line + local buf="" + while (line ~= nil) do + buf = buf .. line + sentLines= sentLines+1 + -- Sent after 1k data + if (string.len(buf) >= 1000) then + line=nil + conn.send(buf) + else + -- fetch the next line + line = file.readLine() + end + end + end + + conn:on("sent", function(conn) + conn:close() + -- Clear the webpage generation + sendWebPage=nil + print("Clean webpage from RAM") + end) + +end + function startWebServer() srv=net.createServer(net.TCP) srv:listen(80,function(conn)