Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
ff392617
Commit
ff392617
authored
Jan 06, 2016
by
devsaurus
Browse files
add fifo to fit new sdk behavior
parent
547ebdf3
Changes
1
Hide whitespace changes
Inline
Side-by-side
lua_examples/telnet2.lua
View file @
ff392617
-- a simple telnet server
s
=
net
.
createServer
(
net
.
TCP
,
180
)
s
:
listen
(
2323
,
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
)
\ No newline at end of file
-- a simple telnet server
telnet_srv
=
net
.
createServer
(
net
.
TCP
,
180
)
telnet_srv
:
listen
(
2323
,
function
(
socket
)
local
fifo
=
{}
local
fifo_drained
=
true
local
function
sender
(
c
)
if
#
fifo
>
0
then
c
:
send
(
table.remove
(
fifo
,
1
))
else
fifo_drained
=
true
end
end
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
)
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment