diff options
author | chai <chaifix@163.com> | 2021-10-20 13:40:34 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-20 13:40:34 +0800 |
commit | ff0f488c97fe8b554b909a0057cebc4c860eac8f (patch) | |
tree | 4e47262b52ffce7e9cfeaaeeab46371243bcaa78 /ThirdParty/luasocket/samples/echosrvr.lua | |
parent | dde719dd575090b36aaa3ad85bb3cabf33f36c5a (diff) |
+luasocket src
Diffstat (limited to 'ThirdParty/luasocket/samples/echosrvr.lua')
-rw-r--r-- | ThirdParty/luasocket/samples/echosrvr.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ThirdParty/luasocket/samples/echosrvr.lua b/ThirdParty/luasocket/samples/echosrvr.lua new file mode 100644 index 0000000..ea564e2 --- /dev/null +++ b/ThirdParty/luasocket/samples/echosrvr.lua @@ -0,0 +1,28 @@ +----------------------------------------------------------------------------- +-- UDP sample: echo protocol server +-- LuaSocket sample files +-- Author: Diego Nehab +----------------------------------------------------------------------------- +local socket = require("socket") +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 = assert(socket.udp()) +assert(udp:setsockname(host, port)) +assert(udp:settimeout(5)) +ip, port = udp:getsockname() +assert(ip, port) +print("Waiting packets on " .. ip .. ":" .. port .. "...") +while 1 do + dgram, ip, port = udp:receivefrom() + if dgram then + print("Echoing '" .. dgram .. "' to " .. ip .. ":" .. port) + udp:sendto(dgram, ip, port) + else + print(ip) + end +end |