【发布时间】:2016-07-04 21:34:07
【问题描述】:
我一直在阅读 NodeMCU 文档和几个关于 SDK 更改的已解决问题,以前允许发送多个数据流(就像排队的 net.socket:send)。
似乎在这里 (#730) 和那里 (#993) 甚至这里 (#999) 引发了一场巨大的争论。但是,我没有找到任何令人信服的网络服务器代码示例,可以让我读取多个 html 文件(例如 head.html 和 body.html)以显示页面。以下是我尝试改编但没有成功的 TerryE 示例:
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on ("receive", function(sck, req)
local response = {}
local f = file.open("head.html","r")
if f ~= nil then
response[#response+1] = file.read()
file.close()
end
local f = file.open("body.html","r")
if f ~= nil then
response[#response+1] = file.read()
file.close()
end
local function sender (sck)
if #response>0 then sck:send(table.remove(response,1))
else sck:close()
end
end
sck:on("sent", sender)
sender(sck)
end )
end )
连接到 ESP8266 时,没有加载任何内容,并且我从 lua 终端没有收到任何错误。
供您参考,head.html 包含:
<html>
<head>
</head>
而body.html 包含:
<body>
<h1>Hello World</h1>
</body>
</html>
我是NodeMCU的新手,请多多包涵。
【问题讨论】:
标签: html sockets lua esp8266 nodemcu