aboutsummaryrefslogtreecommitdiff
path: root/samples/listener.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-05-30 21:36:22 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-05-30 21:36:22 +0000
commit5ca1049ab47f3f9ff9157f71af9072f04a637500 (patch)
tree24fcb14f2890900a4a709312ab25bfc2c14a3939 /samples/listener.lua
parentc23240726e3044e3eaa32a82a999b754c08bc183 (diff)
downloadluasocket-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.lua15
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-----------------------------------------------------------------------------
7require("socket")
7host = host or "*" 8host = host or "*"
8port = port or 8080 9port = port or 8080
9if arg then 10if arg then
@@ -11,18 +12,10 @@ if arg then
11 port = arg[2] or port 12 port = arg[2] or port
12end 13end
13print("Binding to host '" ..host.. "' and port " ..port.. "...") 14print("Binding to host '" ..host.. "' and port " ..port.. "...")
14s, e = socket.bind(host, port) 15s = socket.try(socket.bind(host, port))
15if not s then 16i, p = socket.try(s:getsockname())
16 print(e)
17 exit()
18end
19i, p = s:getsockname()
20print("Waiting connection from talker on " .. i .. ":" .. p .. "...") 17print("Waiting connection from talker on " .. i .. ":" .. p .. "...")
21c, e = s:accept() 18c = socket.try(s:accept())
22if not c then
23 print(e)
24 exit()
25end
26print("Connected. Here is the stuff:") 19print("Connected. Here is the stuff:")
27l, e = c:receive() 20l, e = c:receive()
28while not e do 21while not e do