Forum: Ruby on Rails Ruby UDP Multicasting Binding Insanity

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B4084fdc8c0512d3402387a87b008035?d=identicon&s=25 Preston Lee (Guest)
on 2007-07-28 02:08
(Received via mailing list)
I'm writing a gem which binds multiple sockets to the same UDP
multicast port, basically like so..

    socket = UDPSocket.new
    socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT,
[1].pack("i_") )
    socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP,
addresses)
    socket.bind(Socket::INADDR_ANY, port)
    data, meta = socket.recvfrom 1024

..which is working fine.. in OS X. But no love on my Solaris 10 x64
box. The problem? AFAICT, the available options come straight from
the platforms C setsockopt implementation, which is platform
dependent, and SO_REUSEPORT isn't defined on Solaris. I haven't
gotten to Windows yet but I'm guessing I'll have the same issue.

So, it seems that Ruby's socket library is a bit fubar in that
Socket's constants..

    irb(main):008:0> Socket.constants.sort.each do |c| p c; end

..vary by platform. Anyone have a Better Way of binding twice (or
more) to the same UDP multicast port--or doing any low-level socket
stuff--in a cross-platform-sane manner?

Preston
This topic is locked and can not be replied to.