first glimmers of networking working
This commit is contained in:
parent
15b43d3092
commit
b793604279
|
@ -100,6 +100,8 @@ In addition to Lua 1.5, Teliva forks or depends on:
|
|||
building text-mode user interfaces. ([Alternative documentation](https://tldp.org/LDP/lpg-0.4.pdf))
|
||||
* The [lcurses](https://github.com/lcurses/lcurses) binding for ncurses.
|
||||
([Documentation](http://lcurses.github.io/lcurses))
|
||||
* The [luasocket](https://w3.impa.br/~diego/software/luasocket) library of
|
||||
networking primitives.
|
||||
* The [Kilo](https://github.com/antirez/kilo) text editor. (Read more about it
|
||||
in this [fantastic walk-through](https://viewsourcecode.org/snaptoken/kilo).)
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
teliva_program = {
|
||||
main = [==[
|
||||
function main()
|
||||
local server = assert(socket.bind("*", 8080))
|
||||
server:settimeout(1)
|
||||
curses.mvaddstr(1, 1, "Server bound and waiting for one request")
|
||||
curses.refresh()
|
||||
local available_sockets, _, error = socket.select({server}, nil)
|
||||
for _, available_socket in ipairs(available_sockets) do
|
||||
local client = available_socket:accept()
|
||||
curses.mvaddstr(2, 1, "Connection received")
|
||||
curses.refresh()
|
||||
client:settimeout(1)
|
||||
local line, error = client:receive()
|
||||
if error then
|
||||
curses.mvaddstr(3, 1, "error")
|
||||
curses.refresh()
|
||||
server:close()
|
||||
else
|
||||
curses.stdscr():mvaddstr(3, 1, "received:")
|
||||
curses.stdscr():mvaddstr(4, 3, line)
|
||||
curses.refresh()
|
||||
end
|
||||
end
|
||||
curses.getch()
|
||||
end]==],
|
||||
}
|
Loading…
Reference in New Issue