diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | network.tlv | 27 |
2 files changed, 29 insertions, 0 deletions
diff --git a/README.md b/README.md index 2d490b2..89194b0 100644 --- a/README.md +++ b/README.md @@ -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).) diff --git a/network.tlv b/network.tlv new file mode 100644 index 0000000..c4c2d10 --- /dev/null +++ b/network.tlv @@ -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]==], +} |