Created
July 4, 2016 16:08
-
-
Save corny/5c0a3d426ccce85bd1589d3fa1508efe to your computer and use it in GitHub Desktop.
Lua UDP example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env lua5.2 | |
-- | |
-- apt install lua5.2 lua-socket | |
-- | |
local socket = require("socket") | |
local udp = assert(socket.udp()) | |
local data | |
udp:settimeout(1) | |
assert(udp:setsockname("*",0)) | |
assert(udp:setpeername("example.com",1234)) | |
for i = 0, 2, 1 do | |
assert(udp:send("ping")) | |
data = udp:receive() | |
if data then | |
break | |
end | |
end | |
if data == nil then | |
print("timeout") | |
else | |
print(data) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment