diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-05-30 21:36:22 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-05-30 21:36:22 +0000 |
commit | 5ca1049ab47f3f9ff9157f71af9072f04a637500 (patch) | |
tree | 24fcb14f2890900a4a709312ab25bfc2c14a3939 /samples/listener.lua | |
parent | c23240726e3044e3eaa32a82a999b754c08bc183 (diff) | |
download | luasocket-5ca1049ab47f3f9ff9157f71af9072f04a637500.tar.gz luasocket-5ca1049ab47f3f9ff9157f71af9072f04a637500.tar.bz2 luasocket-5ca1049ab47f3f9ff9157f71af9072f04a637500.zip |
Fine tuning the "require" business.
Diffstat (limited to 'samples/listener.lua')
-rw-r--r-- | samples/listener.lua | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/samples/listener.lua b/samples/listener.lua index dff4d25..bedbde5 100644 --- a/samples/listener.lua +++ b/samples/listener.lua | |||
@@ -4,6 +4,7 @@ | |||
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- RCS ID: $Id$ | 5 | -- RCS ID: $Id$ |
6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
7 | require("socket") | ||
7 | host = host or "*" | 8 | host = host or "*" |
8 | port = port or 8080 | 9 | port = port or 8080 |
9 | if arg then | 10 | if arg then |
@@ -11,18 +12,10 @@ if arg then | |||
11 | port = arg[2] or port | 12 | port = arg[2] or port |
12 | end | 13 | end |
13 | print("Binding to host '" ..host.. "' and port " ..port.. "...") | 14 | print("Binding to host '" ..host.. "' and port " ..port.. "...") |
14 | s, e = socket.bind(host, port) | 15 | s = socket.try(socket.bind(host, port)) |
15 | if not s then | 16 | i, p = socket.try(s:getsockname()) |
16 | print(e) | ||
17 | exit() | ||
18 | end | ||
19 | i, p = s:getsockname() | ||
20 | print("Waiting connection from talker on " .. i .. ":" .. p .. "...") | 17 | print("Waiting connection from talker on " .. i .. ":" .. p .. "...") |
21 | c, e = s:accept() | 18 | c = socket.try(s:accept()) |
22 | if not c then | ||
23 | print(e) | ||
24 | exit() | ||
25 | end | ||
26 | print("Connected. Here is the stuff:") | 19 | print("Connected. Here is the stuff:") |
27 | l, e = c:receive() | 20 | l, e = c:receive() |
28 | while not e do | 21 | while not e do |