The sleep in a worker can be replaced with the following, which will stop sleeping when a UDP packet is received.
require 'socket'
require 'ipaddr'
MULTICAST_ADDR = "ff82::44:1202:901:222"
PORT = 3003
BIND_ADDR = '::'
socket = UDPSocket.new(Socket::AF_INET6)
membership = IPAddr.new(MULTICAST_ADDR).hton + IPAddr.new(BIND_ADDR).hton
socket.setsockopt(:IPPROTO_IPV6, :IPV6_JOIN_GROUP, membership)
socket.setsockopt(:SOL_SOCKET, :SO_REUSEPORT, 1)
socket.bind(BIND_ADDR, PORT)
loop do
s = Kernel.select([socket],[],[],10)
if s
socket.recvfrom(1)
puts 'triggered'
else
puts 'timed out'
end
end
This can be triggered as follows.
require 'socket'
MULTICAST_ADDR = "ff82::44:1202:901:222"
PORT = 3003
socket = UDPSocket.new(Socket::AF_INET6)
socket.setsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL, 1)
socket.send('GO! GO NOW! DO IT!!!!', 0, MULTICAST_ADDR, PORT)
The sleep in a worker can be replaced with the following, which will stop sleeping when a UDP packet is received.
This can be triggered as follows.