socketry/async-io

Is multicast supported now?

tan-wei opened this issue · 3 comments

After a glance of the source code, I guess not. Multicast can be supported when a flag is set.
If not, any workaround? Thanks!
BTW, #7 mentions about a platform related flag SO_REUSEPORT, which may make it hard to workaround.

As a reference, Multicast in Ruby gives us a snippet. For following is about multicast joiner:

require "socket"
require "ipaddr"

MULTICAST_ADDR = "224.0.0.1"
BIND_ADDR = "0.0.0.0"
PORT = 3000

socket = UDPSocket.new
membership = IPAddr.new(MULTICAST_ADDR).hton + IPAddr.new(BIND_ADDR).hton

socket.setsockopt(:IPPROTO_IP, :IP_ADD_MEMBERSHIP, membership)
socket.setsockopt(:SOL_SOCKET, :SO_REUSEPORT, 1)

socket.bind(BIND_ADDR, PORT)

loop do
  message, _ = socket.recvfrom(255)
  puts message
end

When I have time, I'll check it, but it should be working.

Nice. Thanks very much.