diff options
Diffstat (limited to 'samples')
-rw-r--r-- | samples/daytimeclnt.lua | 6 | ||||
-rw-r--r-- | samples/echoclnt.lua | 12 | ||||
-rw-r--r-- | samples/echosrvr.lua | 6 | ||||
-rw-r--r-- | samples/listener.lua | 6 |
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 |
6 | end | 6 | end |
7 | host = toip(host) | 7 | host = socket.toip(host) |
8 | udp = udpsocket() | 8 | udp = socket.udp() |
9 | print("Using host '" ..host.. "' and port " ..port.. "...") | 9 | print("Using host '" ..host.. "' and port " ..port.. "...") |
10 | err = udp:sendto("anything", host, port) | 10 | err = udp:sendto("anything", host, port) |
11 | if err then print(err) exit() end | 11 | if err then print(err) exit() end |
12 | dgram, err = udp:receive() | 12 | dgram, err = udp:receive() |
13 | if not dgram then print(err) exit() end | 13 | if not dgram then print(err) exit() end |
14 | write(dgram) | 14 | io.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 |
6 | end | 6 | end |
7 | host = toip(host) | 7 | host = socket.toip(host) |
8 | udp, err = udpsocket() | 8 | udp, err = socket.udp() |
9 | if not udp then print(err) exit() end | 9 | if not udp then print(err) exit() end |
10 | err = udp:setpeername(host, port) | 10 | err = udp:setpeername(host, port) |
11 | if err then print(err) exit() end | 11 | if err then print(err) exit() end |
12 | print("Using host '" ..host.. "' and port " .. port .. "...") | 12 | print("Using host '" ..host.. "' and port " .. port .. "...") |
13 | while 1 do | 13 | while 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) |
21 | end | 21 | end |
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 |
6 | end | 6 | end |
7 | print("Binding to host '" ..host.. "' and port " ..port.. "...") | 7 | print("Binding to host '" ..host.. "' and port " ..port.. "...") |
8 | udp, err = udpsocket() | 8 | udp, err = socket.udp() |
9 | if not udp then print(err) exit() end | 9 | if not udp then print(err) os.exit() end |
10 | err = udp:setsockname(host, port) | 10 | err = udp:setsockname(host, port) |
11 | if err then print(err) exit() end | 11 | if err then print(err) os.exit() end |
12 | udp:timeout(5) | 12 | udp:timeout(5) |
13 | ip, port = udp:getsockname() | 13 | ip, port = udp:getsockname() |
14 | print("Waiting packets on " .. ip .. ":" .. port .. "...") | 14 | print("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 | ----------------------------------------------------------------------------- | ||
1 | host = host or "*" | 5 | host = host or "*" |
2 | port = port or 8080 | 6 | port = port or 8080 |
3 | if arg then | 7 | if arg then |
@@ -5,7 +9,7 @@ if arg then | |||
5 | port = arg[2] or port | 9 | port = arg[2] or port |
6 | end | 10 | end |
7 | print("Binding to host '" ..host.. "' and port " ..port.. "...") | 11 | print("Binding to host '" ..host.. "' and port " ..port.. "...") |
8 | s, e = bind(host, port) | 12 | s, e = socket.bind(host, port) |
9 | if not s then | 13 | if not s then |
10 | print(e) | 14 | print(e) |
11 | exit() | 15 | exit() |