diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2000-12-29 22:15:09 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2000-12-29 22:15:09 +0000 |
commit | 17c4d1c30544f0ed638879835f179ada96249868 (patch) | |
tree | 46ca8042ba8fda147f56af61e26ec2ceec41f614 /samples/listener.lua | |
parent | 6f9d15b66027cef58441549f8ac0603ca42da0ac (diff) | |
download | luasocket-17c4d1c30544f0ed638879835f179ada96249868.tar.gz luasocket-17c4d1c30544f0ed638879835f179ada96249868.tar.bz2 luasocket-17c4d1c30544f0ed638879835f179ada96249868.zip |
Initial revision
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) | ||