async-io icon indicating copy to clipboard operation
async-io copied to clipboard

Is multicast supported now?

Open tan-wei opened this issue 5 years ago • 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.

tan-wei avatar Mar 27 '20 09:03 tan-wei

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

tan-wei avatar Mar 27 '20 09:03 tan-wei

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

ioquatix avatar Jun 02 '20 13:06 ioquatix

Nice. Thanks very much.

tan-wei avatar Jun 04 '20 10:06 tan-wei