diff options
Diffstat (limited to 'samples')
-rw-r--r-- | samples/README | 2 | ||||
-rw-r--r-- | samples/echoclnt.lua | 10 | ||||
-rw-r--r-- | samples/echosrvr.lua | 9 | ||||
-rw-r--r-- | samples/listener.lua | 7 | ||||
-rw-r--r-- | samples/talker.lua | 4 | ||||
-rw-r--r-- | samples/tinyirc.lua | 4 |
6 files changed, 19 insertions, 17 deletions
diff --git a/samples/README b/samples/README index 3ce4067..0100a4a 100644 --- a/samples/README +++ b/samples/README | |||
@@ -7,7 +7,7 @@ is not supported. | |||
7 | listener.lua and talker.lua are about the simplest applications you can | 7 | listener.lua and talker.lua are about the simplest applications you can |
8 | write using LuaSocket. Run | 8 | write using LuaSocket. Run |
9 | 9 | ||
10 | 'lua listen.lua' and 'lua talk.lua' | 10 | 'lua listener.lua' and 'lua talker.lua' |
11 | 11 | ||
12 | on different terminals. Whatever you type on talk.lua will be | 12 | on different terminals. Whatever you type on talk.lua will be |
13 | printed by listen.lua. | 13 | printed by listen.lua. |
diff --git a/samples/echoclnt.lua b/samples/echoclnt.lua index 038061d..764e433 100644 --- a/samples/echoclnt.lua +++ b/samples/echoclnt.lua | |||
@@ -12,13 +12,13 @@ if arg then | |||
12 | port = arg[2] or port | 12 | port = arg[2] or port |
13 | end | 13 | end |
14 | host = socket.dns.toip(host) | 14 | host = socket.dns.toip(host) |
15 | udp = socket.try(socket.udp()) | 15 | udp = assert(socket.udp()) |
16 | socket.try(udp:setpeername(host, port)) | 16 | assert(udp:setpeername(host, port)) |
17 | print("Using remote host '" ..host.. "' and port " .. port .. "...") | 17 | print("Using remote host '" ..host.. "' and port " .. port .. "...") |
18 | while 1 do | 18 | while 1 do |
19 | line = io.read() | 19 | line = io.read() |
20 | if not line then os.exit() end | 20 | if not line or line == "" then os.exit() end |
21 | socket.try(udp:send(line)) | 21 | assert(udp:send(line)) |
22 | dgram = socket.try(udp:receive()) | 22 | dgram = assert(udp:receive()) |
23 | print(dgram) | 23 | print(dgram) |
24 | end | 24 | end |
diff --git a/samples/echosrvr.lua b/samples/echosrvr.lua index 3ebbe85..d4449e5 100644 --- a/samples/echosrvr.lua +++ b/samples/echosrvr.lua | |||
@@ -12,10 +12,11 @@ if arg then | |||
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 | udp = socket.try(socket.udp()) | 15 | udp = assert(socket.udp()) |
16 | socket.try(udp:setsockname(host, port)) | 16 | assert(udp:setsockname(host, port)) |
17 | socket.try(udp:settimeout(5)) | 17 | assert(udp:settimeout(5)) |
18 | ip, port = socket.try(udp:getsockname()) | 18 | ip, port = udp:getsockname() |
19 | assert(ip, port) | ||
19 | print("Waiting packets on " .. ip .. ":" .. port .. "...") | 20 | print("Waiting packets on " .. ip .. ":" .. port .. "...") |
20 | while 1 do | 21 | while 1 do |
21 | dgram, ip, port = udp:receivefrom() | 22 | dgram, ip, port = udp:receivefrom() |
diff --git a/samples/listener.lua b/samples/listener.lua index 65c6501..4d4c3b6 100644 --- a/samples/listener.lua +++ b/samples/listener.lua | |||
@@ -12,10 +12,11 @@ if arg then | |||
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 = assert(socket.bind(host, port)) |
16 | i, p = socket.try(s:getsockname()) | 16 | i, p = s:getsockname() |
17 | assert(i, p) | ||
17 | print("Waiting connection from talker on " .. i .. ":" .. p .. "...") | 18 | print("Waiting connection from talker on " .. i .. ":" .. p .. "...") |
18 | c = socket.try(s:accept()) | 19 | c = assert(s:accept()) |
19 | print("Connected. Here is the stuff:") | 20 | print("Connected. Here is the stuff:") |
20 | l, e = c:receive() | 21 | l, e = c:receive() |
21 | while not e do | 22 | while not e do |
diff --git a/samples/talker.lua b/samples/talker.lua index 3f6e69c..901ed2c 100644 --- a/samples/talker.lua +++ b/samples/talker.lua | |||
@@ -12,10 +12,10 @@ if arg then | |||
12 | port = arg[2] or port | 12 | port = arg[2] or port |
13 | end | 13 | end |
14 | print("Attempting connection to host '" ..host.. "' and port " ..port.. "...") | 14 | print("Attempting connection to host '" ..host.. "' and port " ..port.. "...") |
15 | c = socket.try(socket.connect(host, port)) | 15 | c = assert(socket.connect(host, port)) |
16 | print("Connected! Please type stuff (empty line to stop):") | 16 | print("Connected! Please type stuff (empty line to stop):") |
17 | l = io.read() | 17 | l = io.read() |
18 | while l and l ~= "" and not e do | 18 | while l and l ~= "" and not e do |
19 | socket.try(c:send(l, "\n")) | 19 | assert(c:send(l .. "\n")) |
20 | l = io.read() | 20 | l = io.read() |
21 | end | 21 | end |
diff --git a/samples/tinyirc.lua b/samples/tinyirc.lua index 13f42ec..684e7c0 100644 --- a/samples/tinyirc.lua +++ b/samples/tinyirc.lua | |||
@@ -14,8 +14,8 @@ if arg then | |||
14 | port2 = arg[3] or port2 | 14 | port2 = arg[3] or port2 |
15 | end | 15 | end |
16 | 16 | ||
17 | server1 = socket.try(socket.bind(host, port1)) | 17 | server1 = assert(socket.bind(host, port1)) |
18 | server2 = socket.try(socket.bind(host, port2)) | 18 | server2 = assert(socket.bind(host, port2)) |
19 | server1:settimeout(1) -- make sure we don't block in accept | 19 | server1:settimeout(1) -- make sure we don't block in accept |
20 | server2:settimeout(1) | 20 | server2:settimeout(1) |
21 | 21 | ||