diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-16 06:48:48 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-16 06:48:48 +0000 |
commit | e4e2223cff658a7016724a625ebbd3dacb92a8f9 (patch) | |
tree | aac49c61149d30bf11219ab8d9989915bf7bee37 /samples | |
parent | 9a79d500eb3e015f5bf579aab714916d49c1f289 (diff) | |
download | luasocket-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.lua | 50 |
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 | ----------------------------------------------------------------------------- |
7 | local socket = require("socket") | 7 | local socket = require("socket") |
8 | host = host or "*" | 8 | host = host or "*" |
9 | port = port or 8080 | 9 | port = port or 8080 |
10 | if arg then | 10 | if 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 |
13 | end | 13 | end |
14 | print("Binding to host '" ..host.. "' and port " ..port.. "...") | 14 | print("Binding to host '" ..host.. "' and port " ..port.. "...") |
15 | s = socket.try(socket.bind(host, port)) | 15 | s = socket.try(socket.bind(host, port)) |
16 | i, p = socket.try(s:getsockname()) | 16 | i, p = socket.try(s:getsockname()) |
17 | print("Waiting connection from talker on " .. i .. ":" .. p .. "...") | 17 | print("Waiting connection from talker on " .. i .. ":" .. p .. "...") |
18 | c = socket.try(s:accept()) | 18 | c = socket.try(s:accept()) |
19 | print("Connected. Here is the stuff:") | 19 | print("Connected. Here is the stuff:") |
20 | l, e = c:receive() | 20 | l, e = c:receive() |
21 | while not e do | 21 | while not e do |
22 | print(l) | 22 | print(l) |
23 | l, e = c:receive() | 23 | l, e = c:receive() |
24 | end | 24 | end |
25 | print(e) | 25 | print(e) |