aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
Diffstat (limited to 'samples')
-rw-r--r--samples/cddb.lua3
-rw-r--r--samples/daytimeclnt.lua1
-rw-r--r--samples/echoclnt.lua15
-rw-r--r--samples/echosrvr.lua21
4 files changed, 20 insertions, 20 deletions
diff --git a/samples/cddb.lua b/samples/cddb.lua
index 0ed7c71..09309e8 100644
--- a/samples/cddb.lua
+++ b/samples/cddb.lua
@@ -1,3 +1,6 @@
1require"luasocket"
2require"http"
3
1if not arg or not arg[1] or not arg[2] then 4if not arg or not arg[1] or not arg[2] then
2 print("luasocket cddb.lua <category> <disc-id> [<server>]") 5 print("luasocket cddb.lua <category> <disc-id> [<server>]")
3 os.exit(1) 6 os.exit(1)
diff --git a/samples/daytimeclnt.lua b/samples/daytimeclnt.lua
index 63f4017..ee7f652 100644
--- a/samples/daytimeclnt.lua
+++ b/samples/daytimeclnt.lua
@@ -4,6 +4,7 @@
4-- Author: Diego Nehab 4-- Author: Diego Nehab
5-- RCS ID: $Id$ 5-- RCS ID: $Id$
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7require"luasocket"
7host = host or "127.0.0.1" 8host = host or "127.0.0.1"
8port = port or 13 9port = port or 13
9if arg then 10if arg then
diff --git a/samples/echoclnt.lua b/samples/echoclnt.lua
index 56bd123..a3d75f3 100644
--- a/samples/echoclnt.lua
+++ b/samples/echoclnt.lua
@@ -4,6 +4,7 @@
4-- Author: Diego Nehab 4-- Author: Diego Nehab
5-- RCS ID: $Id$ 5-- RCS ID: $Id$
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7require"luasocket"
7host = host or "localhost" 8host = host or "localhost"
8port = port or 7 9port = port or 7
9if arg then 10if arg then
@@ -11,17 +12,13 @@ if arg then
11 port = arg[2] or port 12 port = arg[2] or port
12end 13end
13host = socket.dns.toip(host) 14host = socket.dns.toip(host)
14udp, err = socket.udp() 15udp = socket.try(socket.udp())
15assert(udp, err) 16socket.try(udp:setpeername(host, port))
16ret, err = udp:setpeername(host, port) 17print("Using remote host '" ..host.. "' and port " .. port .. "...")
17assert(ret, err)
18print("Using host '" ..host.. "' and port " .. port .. "...")
19while 1 do 18while 1 do
20 line = io.read() 19 line = io.read()
21 if not line then os.exit() end 20 if not line then os.exit() end
22 ret, err = udp:send(line) 21 socket.try(udp:send(line))
23 if not ret then print(err) os.exit() end 22 dgram = socket.try(udp:receive())
24 dgram, err = udp:receive()
25 if not dgram then print(err) os.exit() end
26 print(dgram) 23 print(dgram)
27end 24end
diff --git a/samples/echosrvr.lua b/samples/echosrvr.lua
index a7ed03c..9d99506 100644
--- a/samples/echosrvr.lua
+++ b/samples/echosrvr.lua
@@ -4,6 +4,7 @@
4-- Author: Diego Nehab 4-- Author: Diego Nehab
5-- RCS ID: $Id$ 5-- RCS ID: $Id$
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7require"luasocket"
7host = host or "127.0.0.1" 8host = host or "127.0.0.1"
8port = port or 7 9port = port or 7
9if arg then 10if arg then
@@ -11,19 +12,17 @@ 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.. "...")
14udp, err = socket.udp() 15udp = socket.try(socket.udp())
15assert(udp, err) 16socket.try(udp:setsockname(host, port))
16ret, err = udp:setsockname(host, port) 17socket.try(udp:settimeout(5))
17assert(ret, err) 18ip, port = socket.try(udp:getsockname())
18udp:settimeout(5)
19ip, port = udp:getsockname()
20assert(ip, port)
21print("Waiting packets on " .. ip .. ":" .. port .. "...") 19print("Waiting packets on " .. ip .. ":" .. port .. "...")
22while 1 do 20while 1 do
23 dgram, ip, port = udp:receivefrom() 21 dgram, ip, port = udp:receivefrom()
24 if not dgram then print(ip) 22 if dgram then
25 else 23 print("Echoing '" .. dgram .. "' to " .. ip .. ":" .. port)
26 print("Echoing from " .. ip .. ":" .. port)
27 udp:sendto(dgram, ip, port) 24 udp:sendto(dgram, ip, port)
28 end 25 else
26 print(ip)
27 end
29end 28end