diff options
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) |
