summaryrefslogtreecommitdiff
path: root/ThirdParty/luasocket/samples/echoclnt.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-20 13:40:34 +0800
committerchai <chaifix@163.com>2021-10-20 13:40:34 +0800
commitff0f488c97fe8b554b909a0057cebc4c860eac8f (patch)
tree4e47262b52ffce7e9cfeaaeeab46371243bcaa78 /ThirdParty/luasocket/samples/echoclnt.lua
parentdde719dd575090b36aaa3ad85bb3cabf33f36c5a (diff)
+luasocket src
Diffstat (limited to 'ThirdParty/luasocket/samples/echoclnt.lua')
-rw-r--r--ThirdParty/luasocket/samples/echoclnt.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/ThirdParty/luasocket/samples/echoclnt.lua b/ThirdParty/luasocket/samples/echoclnt.lua
new file mode 100644
index 0000000..bb22557
--- /dev/null
+++ b/ThirdParty/luasocket/samples/echoclnt.lua
@@ -0,0 +1,23 @@
+-----------------------------------------------------------------------------
+-- UDP sample: echo protocol client
+-- LuaSocket sample files
+-- Author: Diego Nehab
+-----------------------------------------------------------------------------
+local socket = require("socket")
+host = host or "localhost"
+port = port or 7
+if arg then
+ host = arg[1] or host
+ port = arg[2] or port
+end
+host = socket.dns.toip(host)
+udp = assert(socket.udp())
+assert(udp:setpeername(host, port))
+print("Using remote host '" ..host.. "' and port " .. port .. "...")
+while 1 do
+ line = io.read()
+ if not line or line == "" then os.exit() end
+ assert(udp:send(line))
+ dgram = assert(udp:receive())
+ print(dgram)
+end