aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-16 06:48:48 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-16 06:48:48 +0000
commite4e2223cff658a7016724a625ebbd3dacb92a8f9 (patch)
treeaac49c61149d30bf11219ab8d9989915bf7bee37 /samples
parent9a79d500eb3e015f5bf579aab714916d49c1f289 (diff)
downloadluasocket-e4e2223cff658a7016724a625ebbd3dacb92a8f9.tar.gz
luasocket-e4e2223cff658a7016724a625ebbd3dacb92a8f9.tar.bz2
luasocket-e4e2223cff658a7016724a625ebbd3dacb92a8f9.zip
Fixed a bunch of stuff. Added mike's patches.
Diffstat (limited to 'samples')
-rw-r--r--samples/listener.lua50
1 files changed, 25 insertions, 25 deletions
diff --git a/samples/listener.lua b/samples/listener.lua
index b2f7a7e..65c6501 100644
--- a/samples/listener.lua
+++ b/samples/listener.lua
@@ -1,25 +1,25 @@
1----------------------------------------------------------------------------- 1-----------------------------------------------------------------------------
2-- TCP sample: Little program to dump lines received at a given port 2-- TCP sample: Little program to dump lines received at a given port
3-- LuaSocket sample files 3-- LuaSocket sample files
4-- Author: Diego Nehab 4-- Author: Diego Nehab
5-- RCS ID: $Id$ 5-- RCS ID: $Id$
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7local socket = require("socket") 7local socket = require("socket")
8host = host or "*" 8host = host or "*"
9port = port or 8080 9port = port or 8080
10if arg then 10if arg then
11 host = arg[1] or host 11 host = arg[1] or host
12 port = arg[2] or port 12 port = arg[2] or port
13end 13end
14print("Binding to host '" ..host.. "' and port " ..port.. "...") 14print("Binding to host '" ..host.. "' and port " ..port.. "...")
15s = socket.try(socket.bind(host, port)) 15s = socket.try(socket.bind(host, port))
16i, p = socket.try(s:getsockname()) 16i, p = socket.try(s:getsockname())
17print("Waiting connection from talker on " .. i .. ":" .. p .. "...") 17print("Waiting connection from talker on " .. i .. ":" .. p .. "...")
18c = socket.try(s:accept()) 18c = socket.try(s:accept())
19print("Connected. Here is the stuff:") 19print("Connected. Here is the stuff:")
20l, e = c:receive() 20l, e = c:receive()
21while not e do 21while not e do
22 print(l) 22 print(l)
23 l, e = c:receive() 23 l, e = c:receive()
24end 24end
25print(e) 25print(e)