使用 nodeMCU 的 esp8266 上的脚本不断运行
Script on esp8266 using nodeMCU constantly runs
我正在使用 lualoader 并从 webserver example
加载了以下脚本
-- a simple http server
srv = net.createServer(net.TCP)
srv:listen(80, function(conn)
conn:on("receive", function(sck, payload)
print(payload)
sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1> Hello, NodeMCU.</h1>")
end)
conn:on("sent", function(sck) sck:close() end)
end)
我将它保存在一个文件中并将其加载到 lualoader 然后 dofile
。每当我加载时,都会向 esp8266 发送 HTTP 请求,它会加载网页。这甚至在 运行 其他脚本之后。从阅读脚本来看,它似乎只能处理一个 HTTP 请求。为什么它一直在处理新的 http 请求?
From reading the script it looks like it can only handle one HTTP request.
不确定你的意思。您可以参考 http://nodemcu.readthedocs.io/en/latest/en/modules/http/ 吗?即发送out个请求,只有1个并发请求。
Why does it keep handling new http requests?
服务器会一直监听,直到您关闭它。
srv:close()
我正在使用 lualoader 并从 webserver example
加载了以下脚本-- a simple http server
srv = net.createServer(net.TCP)
srv:listen(80, function(conn)
conn:on("receive", function(sck, payload)
print(payload)
sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1> Hello, NodeMCU.</h1>")
end)
conn:on("sent", function(sck) sck:close() end)
end)
我将它保存在一个文件中并将其加载到 lualoader 然后 dofile
。每当我加载时,都会向 esp8266 发送 HTTP 请求,它会加载网页。这甚至在 运行 其他脚本之后。从阅读脚本来看,它似乎只能处理一个 HTTP 请求。为什么它一直在处理新的 http 请求?
From reading the script it looks like it can only handle one HTTP request.
不确定你的意思。您可以参考 http://nodemcu.readthedocs.io/en/latest/en/modules/http/ 吗?即发送out个请求,只有1个并发请求。
Why does it keep handling new http requests?
服务器会一直监听,直到您关闭它。
srv:close()