From 17c4d1c30544f0ed638879835f179ada96249868 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 29 Dec 2000 22:15:09 +0000 Subject: Initial revision --- samples/README | 32 ++++++++++++++++++++++++++++++++ samples/listener.lua | 25 +++++++++++++++++++++++++ samples/talker.lua | 22 ++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 samples/README create mode 100644 samples/listener.lua create mode 100644 samples/talker.lua (limited to 'samples') diff --git a/samples/README b/samples/README new file mode 100644 index 0000000..ef5017b --- /dev/null +++ b/samples/README @@ -0,0 +1,32 @@ +This directory contains some sample programs using LuaSocket as well as +the automatic tests used to make sure the library is working properly. + +The files provided are: + + server.lua -- test server + client.lua -- test client + command.lua -- test command definitions + +The automatic tests are composed by three files: client.lua, command.lua +and server.lua. To run the automatic tests on your system, make sure to +compile the library with _DEBUG defined (check makefile) and then open +two terminals. Run 'luasocket server.lua' on one of them and 'luasocket +client.lua' on the other. The programs should start talking to each +other. + + listen.lua -- echo server + talk.lua -- echo tester + +listen.lua and talk.lua are about the simplest applications you can +write using LuaSocket. Run 'luasocket listen.lua' and 'luasocket +talk.lua' on different terminals. Whatever you type on talk.lua will be +printed by listen.lua. + + dict.lua -- dict client + +The dict.lua module is a cool simple client for the DICT protocol, +written by Luiz Henrique Figueiredo. Just run it and enter a few words +to see it working. + +Good luck, +Diego. diff --git a/samples/listener.lua b/samples/listener.lua new file mode 100644 index 0000000..a47d9a3 --- /dev/null +++ b/samples/listener.lua @@ -0,0 +1,25 @@ +host = "localhost" +port = 8080 +if arg then + host = arg[1] or host + port = arg[2] or port +end +print("Binding to host '" ..host.. "' and port " ..port.. "...") +s, i, p, e = bind(host, port) +if not s then + print(e) + exit() +end +print("Waiting connection from talker on " .. i .. ":" .. p .. "...") +c, e = s:accept() +if not c then + print(e) + exit() +end +print("Connected. Here is the stuff:") +l, e = c:receive() +while not e do + print(l) + l, e = c:receive() +end +print(e) diff --git a/samples/talker.lua b/samples/talker.lua new file mode 100644 index 0000000..b3313e6 --- /dev/null +++ b/samples/talker.lua @@ -0,0 +1,22 @@ +host = "localhost" +port = 8080 +if arg then + host = arg[1] or host + port = arg[2] or port +end +print("Attempting connection to host '" ..host.. "' and port " ..port.. "...") +c, e = connect(host, port) +if not c then + print(e) + exit() +end +print("Connected! Please type stuff (empty line to stop):") +l = read() +while l and l ~= "" and not e do + e = c:send(l, "\n") + if e then + print(e) + exit() + end + l = read() +end -- cgit v1.2.3-55-g6feb