aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
Diffstat (limited to 'samples')
-rw-r--r--samples/daytimeclnt.lua6
-rw-r--r--samples/echoclnt.lua12
-rw-r--r--samples/echosrvr.lua6
-rw-r--r--samples/listener.lua6
4 files changed, 17 insertions, 13 deletions
diff --git a/samples/daytimeclnt.lua b/samples/daytimeclnt.lua
index 1107c6a..000dfd5 100644
--- a/samples/daytimeclnt.lua
+++ b/samples/daytimeclnt.lua
@@ -4,11 +4,11 @@ if arg then
4 host = arg[1] or host 4 host = arg[1] or host
5 port = arg[2] or port 5 port = arg[2] or port
6end 6end
7host = toip(host) 7host = socket.toip(host)
8udp = udpsocket() 8udp = socket.udp()
9print("Using host '" ..host.. "' and port " ..port.. "...") 9print("Using host '" ..host.. "' and port " ..port.. "...")
10err = udp:sendto("anything", host, port) 10err = udp:sendto("anything", host, port)
11if err then print(err) exit() end 11if err then print(err) exit() end
12dgram, err = udp:receive() 12dgram, err = udp:receive()
13if not dgram then print(err) exit() end 13if not dgram then print(err) exit() end
14write(dgram) 14io.write(dgram)
diff --git a/samples/echoclnt.lua b/samples/echoclnt.lua
index 043b2f0..cd8b450 100644
--- a/samples/echoclnt.lua
+++ b/samples/echoclnt.lua
@@ -4,18 +4,18 @@ if arg then
4 host = arg[1] or host 4 host = arg[1] or host
5 port = arg[2] or port 5 port = arg[2] or port
6end 6end
7host = toip(host) 7host = socket.toip(host)
8udp, err = udpsocket() 8udp, err = socket.udp()
9if not udp then print(err) exit() end 9if not udp then print(err) exit() end
10err = udp:setpeername(host, port) 10err = udp:setpeername(host, port)
11if err then print(err) exit() end 11if err then print(err) exit() end
12print("Using host '" ..host.. "' and port " .. port .. "...") 12print("Using host '" ..host.. "' and port " .. port .. "...")
13while 1 do 13while 1 do
14 line = read() 14 line = io.read()
15 if not line then exit() end 15 if not line then os.exit() end
16 err = udp:send(line) 16 err = udp:send(line)
17 if err then print(err) exit() end 17 if err then print(err) os.exit() end
18 dgram, err = udp:receive() 18 dgram, err = udp:receive()
19 if not dgram then print(err) exit() end 19 if not dgram then print(err) os.exit() end
20 print(dgram) 20 print(dgram)
21end 21end
diff --git a/samples/echosrvr.lua b/samples/echosrvr.lua
index 330f9e6..6117557 100644
--- a/samples/echosrvr.lua
+++ b/samples/echosrvr.lua
@@ -5,10 +5,10 @@ if arg then
5 port = arg[2] or port 5 port = arg[2] or port
6end 6end
7print("Binding to host '" ..host.. "' and port " ..port.. "...") 7print("Binding to host '" ..host.. "' and port " ..port.. "...")
8udp, err = udpsocket() 8udp, err = socket.udp()
9if not udp then print(err) exit() end 9if not udp then print(err) os.exit() end
10err = udp:setsockname(host, port) 10err = udp:setsockname(host, port)
11if err then print(err) exit() end 11if err then print(err) os.exit() end
12udp:timeout(5) 12udp:timeout(5)
13ip, port = udp:getsockname() 13ip, port = udp:getsockname()
14print("Waiting packets on " .. ip .. ":" .. port .. "...") 14print("Waiting packets on " .. ip .. ":" .. port .. "...")
diff --git a/samples/listener.lua b/samples/listener.lua
index 8e2c7ce..c035ab2 100644
--- a/samples/listener.lua
+++ b/samples/listener.lua
@@ -1,3 +1,7 @@
1-----------------------------------------------------------------------------
2-- Little program to dump lines received at a given port
3-- LuaSocket 1.5 sample files
4-----------------------------------------------------------------------------
1host = host or "*" 5host = host or "*"
2port = port or 8080 6port = port or 8080
3if arg then 7if arg then
@@ -5,7 +9,7 @@ if arg then
5 port = arg[2] or port 9 port = arg[2] or port
6end 10end
7print("Binding to host '" ..host.. "' and port " ..port.. "...") 11print("Binding to host '" ..host.. "' and port " ..port.. "...")
8s, e = bind(host, port) 12s, e = socket.bind(host, port)
9if not s then 13if not s then
10 print(e) 14 print(e)
11 exit() 15 exit()