Change telnet server to work on the console rather than the uart

This commit is contained in:
Ryan Voots 2016-05-01 15:33:56 -07:00
parent cdfb1b8071
commit dd25fdee4d

View file

@ -1,19 +1,19 @@
return function(port)
function connected(conn)
negotiate = string.char(255, 253, 34, 255, 250, 34, 1, 0, 255, 240, 255, 251, 1)
conn:send(negotiate)
conn:on("receive", function(conn, pl)
conn:send('.')
uart.write(0, pl)
end)
end
function startTelnet()
print("Starting Telnet server")
sv = net.createServer(net.TCP, 180)
sv:listen(23, connected)
print("Telnet server now started")
end
startTelnet()
-- uart.setup(0, 9600, 8, 0, 1, 0)
-- a simple telnet server
s=net.createServer(net.TCP,180)
s:listen(port,function(c)
function s_output(str)
if(c~=nil)
then c:send(str)
end
end
node.output(s_output, 0) -- re-direct output to function s_ouput.
c:on("receive",function(c,l)
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
end)
c:on("disconnection",function(c)
node.output(nil) -- un-regist the redirect output function, output goes to serial
end)
print("Welcome to NodeMcu world.")
end)
end