aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
Diffstat (limited to 'samples')
-rw-r--r--samples/cddb.lua12
-rw-r--r--samples/echosrvr.lua6
-rw-r--r--samples/lpr.lua3
-rw-r--r--samples/tinyirc.lua10
4 files changed, 16 insertions, 15 deletions
diff --git a/samples/cddb.lua b/samples/cddb.lua
index 482dc98..883730c 100644
--- a/samples/cddb.lua
+++ b/samples/cddb.lua
@@ -16,7 +16,7 @@ function parse(body)
16 return nil, code, message 16 return nil, code, message
17 end 17 end
18 local data = {} 18 local data = {}
19 for l in lines do 19 for l in lines do
20 local c = string.sub(l, 1, 1) 20 local c = string.sub(l, 1, 1)
21 if c ~= '#' and c ~= '.' then 21 if c ~= '#' and c ~= '.' then
22 local key, value = socket.skip(2, string.find(l, "(.-)=(.*)")) 22 local key, value = socket.skip(2, string.find(l, "(.-)=(.*)"))
@@ -26,7 +26,7 @@ function parse(body)
26 data[key] = value 26 data[key] = value
27 end 27 end
28 end 28 end
29 return data, code, message 29 return data, code, message
30end 30end
31 31
32local host = socket.dns.gethostname() 32local host = socket.dns.gethostname()
@@ -34,13 +34,13 @@ local query = "%s?cmd=cddb+read+%s+%s&hello=LuaSocket+%s+LuaSocket+2.0&proto=6"
34local url = string.format(query, server, arg[1], arg[2], host) 34local url = string.format(query, server, arg[1], arg[2], host)
35local body, headers, code = http.get(url) 35local body, headers, code = http.get(url)
36 36
37if code == 200 then 37if code == 200 then
38 local data, code, error = parse(body) 38 local data, code, error = parse(body)
39 if not data then 39 if not data then
40 print(error or code) 40 print(error or code)
41 else 41 else
42 for i,v in pairs(data) do 42 for i,v in pairs(data) do
43 io.write(i, ': ', v, '\n') 43 io.write(i, ': ', v, '\n')
44 end 44 end
45 end 45 end
46else print(error) end 46else print(error) end
diff --git a/samples/echosrvr.lua b/samples/echosrvr.lua
index d4449e5..8d39ed9 100644
--- a/samples/echosrvr.lua
+++ b/samples/echosrvr.lua
@@ -20,10 +20,10 @@ assert(ip, port)
20print("Waiting packets on " .. ip .. ":" .. port .. "...") 20print("Waiting packets on " .. ip .. ":" .. port .. "...")
21while 1 do 21while 1 do
22 dgram, ip, port = udp:receivefrom() 22 dgram, ip, port = udp:receivefrom()
23 if dgram then 23 if dgram then
24 print("Echoing '" .. dgram .. "' to " .. ip .. ":" .. port) 24 print("Echoing '" .. dgram .. "' to " .. ip .. ":" .. port)
25 udp:sendto(dgram, ip, port) 25 udp:sendto(dgram, ip, port)
26 else 26 else
27 print(ip) 27 print(ip)
28 end 28 end
29end 29end
diff --git a/samples/lpr.lua b/samples/lpr.lua
index 5ab4d69..2b059b1 100644
--- a/samples/lpr.lua
+++ b/samples/lpr.lua
@@ -36,7 +36,8 @@ do
36 return usage() 36 return usage()
37 end 37 end
38 if arg[1] ~= "query" then 38 if arg[1] ~= "query" then
39 r,e=lp.send(arg[1],opt) 39 opt.file = arg[1]
40 r,e=lp.send(opt)
40 io.stdout:write(tostring(r or e),'\n') 41 io.stdout:write(tostring(r or e),'\n')
41 else 42 else
42 r,e=lp.query(opt) 43 r,e=lp.query(opt)
diff --git a/samples/tinyirc.lua b/samples/tinyirc.lua
index e3dd517..dd2c6f8 100644
--- a/samples/tinyirc.lua
+++ b/samples/tinyirc.lua
@@ -62,24 +62,24 @@ while 1 do
62 if input == server1 or input == server2 then 62 if input == server1 or input == server2 then
63 io.write("Waiting for clients\n") 63 io.write("Waiting for clients\n")
64 local new = input:accept() 64 local new = input:accept()
65 if new then 65 if new then
66 new:settimeout(1) 66 new:settimeout(1)
67 io.write("Inserting client in set\n") 67 io.write("Inserting client in set\n")
68 set:insert(new) 68 set:insert(new)
69 end 69 end
70 -- it is a client socket 70 -- it is a client socket
71 else 71 else
72 local line, error = input:receive() 72 local line, error = input:receive()
73 if error then 73 if error then
74 input:close() 74 input:close()
75 io.write("Removing client from set\n") 75 io.write("Removing client from set\n")
76 set:remove(input) 76 set:remove(input)
77 else 77 else
78 io.write("Broadcasting line '", line, "'\n") 78 io.write("Broadcasting line '", line, "'\n")
79 writable, error = socket.skip(1, socket.select(nil, set, 1)) 79 writable, error = socket.skip(1, socket.select(nil, set, 1))
80 if not error then 80 if not error then
81 for __, output in ipairs(writable) do 81 for __, output in ipairs(writable) do
82 if output ~= input then 82 if output ~= input then
83 output:send(line .. "\n") 83 output:send(line .. "\n")
84 end 84 end
85 end 85 end