# Ruby UDP Multicasting Binding Insanity

**URL:** <https://www.ruby-forum.com/t/ruby-udp-multicasting-binding-insanity/110614>\
**Category:** Rails\
**Created:** [July 28, 2007, 2:08am UTC](https://www.ruby-forum.com/t/ruby-udp-multicasting-binding-insanity/110614 "2007-07-28T02:08:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![preston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@preston](https://www.ruby-forum.com/u/preston)\
**Post date:** [July 28, 2007, 2:08am UTC](https://www.ruby-forum.com/t/ruby-udp-multicasting-binding-insanity/110614/1 "2007-07-28T02:08:21Z")

</div>

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
