From 604267dbffcad6ef320c54f9cef15409055a9816 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Sat, 26 Jan 2019 18:42:13 +0100 Subject: [PATCH] Mon serveur HTML fonctionne bien maintenant, mais pas encore le serveur ASP ! --- ZYX-html-framework/index.html | 7 ++----- ZYX-html-framework/page1.html | 4 ++-- ZYX-html-framework/page2.html | 4 ++-- ZYX-html-framework/web_srv2.lua | 29 ++++++++++++++++------------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ZYX-html-framework/index.html b/ZYX-html-framework/index.html index 4a02c7c..d735f3b 100644 --- a/ZYX-html-framework/index.html +++ b/ZYX-html-framework/index.html @@ -7,16 +7,13 @@ -

ESP8266 home page 190126.1757

-
___________________

-

Différentes pages HTML:

+

ESP8266 home page 190126.1836

+

Différentes pages HTML:

Page 1
Page 2
Page qui n'existe pas !

-
___________________
- diff --git a/ZYX-html-framework/page1.html b/ZYX-html-framework/page1.html index 8f0d66e..09ad16c 100644 --- a/ZYX-html-framework/page1.html +++ b/ZYX-html-framework/page1.html @@ -7,10 +7,10 @@ -

ESP8266 page 1 190126.1757

+

ESP8266 page 1 190126.1841


Coucou c'est la page 1 !
- Retour à la home page...
+ Retour à la home page...
diff --git a/ZYX-html-framework/page2.html b/ZYX-html-framework/page2.html index 1cc6d6e..85b7355 100644 --- a/ZYX-html-framework/page2.html +++ b/ZYX-html-framework/page2.html @@ -7,10 +7,10 @@ -

ESP8266 page 2 190126.1757

+

ESP8266 page 2 190126.1840


Coucou c'est la page 2 !
- Retour à la home page...
+ Retour à la home page...
diff --git a/ZYX-html-framework/web_srv2.lua b/ZYX-html-framework/web_srv2.lua index cb9ff54..64b02a0 100644 --- a/ZYX-html-framework/web_srv2.lua +++ b/ZYX-html-framework/web_srv2.lua @@ -1,20 +1,24 @@ --- petit script de serveur WEB avec Active Server Page Zyx +-- petit script de serveur WEB avec Active Server Page ZYX -print("\n web_srv2.lua zf190126.1658 \n") +print("\n web_srv2.lua zf190126.1837 \n") -- send a file from memory to the client; max. line length = 1024 bytes! -function send_file(client, filename) - if file.open(filename, "r") then - repeat - local line=file.read('\n') - if line then - client:send(line) - end - until not line - file.close() - end +function send_file(zclient, zfilename) + if zfilename == "" then zfilename = "index.html" end + if file.open(zfilename, "r") then + repeat + local line=file.read('\n') + if line then + zclient:send(line) + end + until not line + file.close() + else + zclient:send("

"..zfilename.." not found - 404 error.

Home
") + end end + srv = net.createServer(net.TCP) srv:listen(80, function(conn) conn:on("receive", function(client, request) @@ -40,7 +44,6 @@ srv:listen(80, function(conn) end file_html=string.gsub(path, "/", "") print("file_html: ",file_html) - send_file(conn, file_html) -- conn:send("

ESP8266
Server is working!

\n\n")