add fifo to fit new sdk behavior
This commit is contained in:
parent
547ebdf3ff
commit
ff3926175c
|
@ -1,17 +1,35 @@
|
||||||
-- a simple telnet server
|
-- a simple telnet server
|
||||||
s=net.createServer(net.TCP,180)
|
|
||||||
s:listen(2323,function(c)
|
telnet_srv = net.createServer(net.TCP, 180)
|
||||||
function s_output(str)
|
telnet_srv:listen(2323, function(socket)
|
||||||
if(c~=nil)
|
local fifo = {}
|
||||||
then c:send(str)
|
local fifo_drained = true
|
||||||
end
|
|
||||||
end
|
local function sender(c)
|
||||||
node.output(s_output, 0) -- re-direct output to function s_ouput.
|
if #fifo > 0 then
|
||||||
c:on("receive",function(c,l)
|
c:send(table.remove(fifo, 1))
|
||||||
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
|
else
|
||||||
end)
|
fifo_drained = true
|
||||||
c:on("disconnection",function(c)
|
end
|
||||||
node.output(nil) -- un-regist the redirect output function, output goes to serial
|
end
|
||||||
end)
|
|
||||||
print("Welcome to NodeMcu world.")
|
local function s_output(str)
|
||||||
|
table.insert(fifo, str)
|
||||||
|
if socket ~= nil and fifo_drained then
|
||||||
|
fifo_drained = false
|
||||||
|
sender(socket)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
node.output(s_output, 0) -- re-direct output to function s_ouput.
|
||||||
|
|
||||||
|
socket:on("receive", function(c, l)
|
||||||
|
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
|
||||||
end)
|
end)
|
||||||
|
socket:on("disconnection", function(c)
|
||||||
|
node.output(nil) -- un-regist the redirect output function, output goes to serial
|
||||||
|
end)
|
||||||
|
socket:on("sent", sender)
|
||||||
|
|
||||||
|
print("Welcome to NodeMcu world.")
|
||||||
|
end)
|
||||||
|
|
Loading…
Reference in New Issue