mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 20:38:22 +01:00
21 lines
692 B
Lua
21 lines
692 B
Lua
local socket = require"socket"
|
|
local group = "225.0.0.37"
|
|
local port = 12345
|
|
local c = assert(socket.udp())
|
|
--print(assert(c:setoption("reuseport", true)))
|
|
--print(assert(c:setsockname("*", port)))
|
|
--print(assert(c:setoption("ip-multicast-loop", false)))
|
|
--print(assert(c:setoption("ip-multicast-ttl", 4)))
|
|
--print(assert(c:setoption("ip-multicast-if", "10.0.1.3")))
|
|
--print(assert(c:setoption("ip-add-membership", {multiaddr = group, interface = "*"})))
|
|
local i = 0
|
|
while 1 do
|
|
local message = string.format("hello all %d!", i)
|
|
assert(c:sendto(message, group, port))
|
|
print("sent " .. message)
|
|
socket.sleep(1)
|
|
c:settimeout(0.5)
|
|
print(c:receivefrom())
|
|
i = i + 1
|
|
end
|