aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
Diffstat (limited to 'samples')
-rw-r--r--samples/daytimeclnt.lua14
-rw-r--r--samples/echoclnt.lua21
-rw-r--r--samples/echosrvr.lua22
3 files changed, 57 insertions, 0 deletions
diff --git a/samples/daytimeclnt.lua b/samples/daytimeclnt.lua
new file mode 100644
index 0000000..94e03d3
--- /dev/null
+++ b/samples/daytimeclnt.lua
@@ -0,0 +1,14 @@
1host = host or "127.0.0.1"
2port = port or 13
3if arg then
4 host = arg[1] or host
5 port = arg[2] or port
6end
7host = toip(host)
8udp = udpsocket()
9print("Using host '" ..host.. "' and port " ..port.. "...")
10err = sendto(udp, "anything", host, port)
11if err then print(err) exit() end
12dgram, err = receive(udp)
13if not dgram then print(err) exit() end
14write(dgram)
diff --git a/samples/echoclnt.lua b/samples/echoclnt.lua
new file mode 100644
index 0000000..d1c56c7
--- /dev/null
+++ b/samples/echoclnt.lua
@@ -0,0 +1,21 @@
1host = host or "localhost"
2port = port or 7
3if arg then
4 host = arg[1] or host
5 port = arg[2] or port
6end
7host = toip(host)
8udp, err = udpsocket()
9if not udp then print(err) exit() end
10err = setpeername(udp, host, port)
11if err then print(err) exit() end
12print("Using host '" ..host.. "' and port " ..port.. "...")
13while 1 do
14 line = read()
15 if not line then exit() end
16 err = send(udp, line)
17 if err then print(err) exit() end
18 dgram, err = receive(udp)
19 if not dgram then print(err) exit() end
20 print(dgram)
21end
diff --git a/samples/echosrvr.lua b/samples/echosrvr.lua
new file mode 100644
index 0000000..fe7da06
--- /dev/null
+++ b/samples/echosrvr.lua
@@ -0,0 +1,22 @@
1host = host or "127.0.0.1"
2port = port or 7
3if arg then
4 host = arg[1] or host
5 port = arg[2] or port
6end
7print("Binding to host '" ..host.. "' and port " ..port.. "...")
8udp, err = udpsocket()
9if not udp then print(err) exit() end
10err = setsockname(udp, host, port)
11if err then print(err) exit() end
12timeout(udp, 5)
13ip, port = getsockname(udp)
14print("Waiting packets on " .. ip .. ":" .. port .. "...")
15while 1 do
16 dgram, ip, port = receivefrom(udp)
17 if not dgram then print(ip)
18 else
19 print("Echoing from " .. ip .. ":" .. port)
20 sendto(udp, dgram, ip, port)
21 end
22end