diff options
Diffstat (limited to 'samples/listener.lua')
-rw-r--r-- | samples/listener.lua | 25 |
1 files changed, 25 insertions, 0 deletions
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 @@ | |||
1 | host = "localhost" | ||
2 | port = 8080 | ||
3 | if arg then | ||
4 | host = arg[1] or host | ||
5 | port = arg[2] or port | ||
6 | end | ||
7 | print("Binding to host '" ..host.. "' and port " ..port.. "...") | ||
8 | s, i, p, e = bind(host, port) | ||
9 | if not s then | ||
10 | print(e) | ||
11 | exit() | ||
12 | end | ||
13 | print("Waiting connection from talker on " .. i .. ":" .. p .. "...") | ||
14 | c, e = s:accept() | ||
15 | if not c then | ||
16 | print(e) | ||
17 | exit() | ||
18 | end | ||
19 | print("Connected. Here is the stuff:") | ||
20 | l, e = c:receive() | ||
21 | while not e do | ||
22 | print(l) | ||
23 | l, e = c:receive() | ||
24 | end | ||
25 | print(e) | ||