From 7096b8df82eebfe857e0043bc8a853353bd78480 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Thu, 25 Jan 2001 21:59:39 +0000 Subject: Initial revision --- samples/daytimeclnt.lua | 14 ++++++++++++++ samples/echoclnt.lua | 21 +++++++++++++++++++++ samples/echosrvr.lua | 22 ++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 samples/daytimeclnt.lua create mode 100644 samples/echoclnt.lua create mode 100644 samples/echosrvr.lua (limited to 'samples') 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 @@ +host = host or "127.0.0.1" +port = port or 13 +if arg then + host = arg[1] or host + port = arg[2] or port +end +host = toip(host) +udp = udpsocket() +print("Using host '" ..host.. "' and port " ..port.. "...") +err = sendto(udp, "anything", host, port) +if err then print(err) exit() end +dgram, err = receive(udp) +if not dgram then print(err) exit() end +write(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 @@ +host = host or "localhost" +port = port or 7 +if arg then + host = arg[1] or host + port = arg[2] or port +end +host = toip(host) +udp, err = udpsocket() +if not udp then print(err) exit() end +err = setpeername(udp, host, port) +if err then print(err) exit() end +print("Using host '" ..host.. "' and port " ..port.. "...") +while 1 do + line = read() + if not line then exit() end + err = send(udp, line) + if err then print(err) exit() end + dgram, err = receive(udp) + if not dgram then print(err) exit() end + print(dgram) +end 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 @@ +host = host or "127.0.0.1" +port = port or 7 +if arg then + host = arg[1] or host + port = arg[2] or port +end +print("Binding to host '" ..host.. "' and port " ..port.. "...") +udp, err = udpsocket() +if not udp then print(err) exit() end +err = setsockname(udp, host, port) +if err then print(err) exit() end +timeout(udp, 5) +ip, port = getsockname(udp) +print("Waiting packets on " .. ip .. ":" .. port .. "...") +while 1 do + dgram, ip, port = receivefrom(udp) + if not dgram then print(ip) + else + print("Echoing from " .. ip .. ":" .. port) + sendto(udp, dgram, ip, port) + end +end -- cgit v1.2.3-55-g6feb