aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
Diffstat (limited to 'samples')
-rw-r--r--samples/README32
-rw-r--r--samples/listener.lua25
-rw-r--r--samples/talker.lua22
3 files changed, 79 insertions, 0 deletions
diff --git a/samples/README b/samples/README
new file mode 100644
index 0000000..ef5017b
--- /dev/null
+++ b/samples/README
@@ -0,0 +1,32 @@
1This directory contains some sample programs using LuaSocket as well as
2the automatic tests used to make sure the library is working properly.
3
4The files provided are:
5
6 server.lua -- test server
7 client.lua -- test client
8 command.lua -- test command definitions
9
10The automatic tests are composed by three files: client.lua, command.lua
11and server.lua. To run the automatic tests on your system, make sure to
12compile the library with _DEBUG defined (check makefile) and then open
13two terminals. Run 'luasocket server.lua' on one of them and 'luasocket
14client.lua' on the other. The programs should start talking to each
15other.
16
17 listen.lua -- echo server
18 talk.lua -- echo tester
19
20listen.lua and talk.lua are about the simplest applications you can
21write using LuaSocket. Run 'luasocket listen.lua' and 'luasocket
22talk.lua' on different terminals. Whatever you type on talk.lua will be
23printed by listen.lua.
24
25 dict.lua -- dict client
26
27The dict.lua module is a cool simple client for the DICT protocol,
28written by Luiz Henrique Figueiredo. Just run it and enter a few words
29to see it working.
30
31Good luck,
32Diego.
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 @@
1host = "localhost"
2port = 8080
3if arg then
4 host = arg[1] or host
5 port = arg[2] or port
6end
7print("Binding to host '" ..host.. "' and port " ..port.. "...")
8s, i, p, e = bind(host, port)
9if not s then
10 print(e)
11 exit()
12end
13print("Waiting connection from talker on " .. i .. ":" .. p .. "...")
14c, e = s:accept()
15if not c then
16 print(e)
17 exit()
18end
19print("Connected. Here is the stuff:")
20l, e = c:receive()
21while not e do
22 print(l)
23 l, e = c:receive()
24end
25print(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 @@
1host = "localhost"
2port = 8080
3if arg then
4 host = arg[1] or host
5 port = arg[2] or port
6end
7print("Attempting connection to host '" ..host.. "' and port " ..port.. "...")
8c, e = connect(host, port)
9if not c then
10 print(e)
11 exit()
12end
13print("Connected! Please type stuff (empty line to stop):")
14l = read()
15while l and l ~= "" and not e do
16 e = c:send(l, "\n")
17 if e then
18 print(e)
19 exit()
20 end
21 l = read()
22end