# Sockets and Fedora Core 9

**URL:** <https://www.ruby-forum.com/t/sockets-and-fedora-core-9/161836>\
**Category:** Ruby\
**Created:** [March 2, 2009, 11:31pm UTC](https://www.ruby-forum.com/t/sockets-and-fedora-core-9/161836 "2009-03-02T23:31:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![clanger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dc4da7/32.png) [@clanger](https://www.ruby-forum.com/u/clanger)\
**Post date:** [March 2, 2009, 11:31pm UTC](https://www.ruby-forum.com/t/sockets-and-fedora-core-9/161836/1 "2009-03-02T23:31:06Z")

</div>

Hello,

Apologies if this is well known or I’m posting in the wrong place.

I have just spent too many hours trying to debug a problem when  
recieving multicasts with UDPSockets… code is as follows:

SERVER=“192.0.0.1” #Real server IP removed for this post  
RECIEVE\_ADDRESS=“0.0.0.0”  
PORT=5001

#Get the address of the server into an IPAddr  
ip = IPAddr.new(SERVER).hton + IPAddr.new(RECIEVE\_ADDRESS).hton

#Create the socket and join the server multicast group  
sock = UDPSocket.new()  
sock.bind(Socket::INADDR\_ANY, PORT)  
sock.setsockopt(Socket::IPPROTO\_IP, Socket::IP\_ADD\_MEMBERSHIP, ip)

puts “Socket has been bound and configured. Waiting for packet”

#Get the packet!  
loop do  
msg = sock.recvfrom(100)  
puts “Recieved Packet. Contents: “#{msg}””  
puts “Waiting for next packet…”  
end

This code worked, but only some of the time. I knew that the server  
(address changed in above code) was multicasting a packet approx every  
10 secs. The above code did recieve packets occasionaly, but spent most  
of the time waiting for recvfrom to return. Several times I let this  
code run for 5+ minutes and nothing was received. I was on a wired LAN  
with the server, so packet loss should not have had such a large effect.

So after much googling, man page reading, and general hair pulling I  
tried this on Fedora Core 5. It works… packets are receieved approx  
every 10 secs. Both machines were on the same wired LAN.

Details of FC5 machine:

$ uname -a  
Linux eng019 2.6.20-1.2320.fc5 #1 Tue Jun 12 18:50:38 EDT 2007 i686  
athlon i386 GNU/Linux  
$ ruby -version  
ruby 1.8.5 (2007-03-13 patchlevel 35) [i386-linux]

Details of FC9 machine:

$ uname -a  
Linux pg012 2.6.25-14.fc9.i686 #1 SMP Thu May 1 06:28:41 EDT 2008 i686  
athlon i386 GNU/Linux  
$ ruby -v  
ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-linux]

Is this a well known issue/is the cause known? If so, are there any work  
arounds to get this working on FC9?

Any input would be appreciated and if more information is needed about  
the machine/environment I will do my best to provide it (note I don’t  
have root access to these machines).

Thanks,  
C

---

<div class="post-metadata">

**Author:** ![clanger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dc4da7/32.png) [@clanger](https://www.ruby-forum.com/u/clanger)\
**Post date:** [March 3, 2009, 12:16am UTC](https://www.ruby-forum.com/t/sockets-and-fedora-core-9/161836/2 "2009-03-03T00:16:50Z")

</div>

Cragi Lagi wrote:

> Any input would be appreciated and if more information is needed about  
> the machine/environment I will do my best to provide it (note I don’t  
> have root access to these machines).

To rule out the difference between ruby 1.8.5 and 1.8.6, you could  
install 1.8.6 on the FC5 machine. You can install to your own account  
with

configure --prefix=/home/me/ruby

or something like that.

---

<div class="post-metadata">

**Author:** ![clanger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dc4da7/32.png) [@clanger](https://www.ruby-forum.com/u/clanger)\
**Post date:** [March 3, 2009, 3:13am UTC](https://www.ruby-forum.com/t/sockets-and-fedora-core-9/161836/3 "2009-03-03T03:13:36Z")

</div>

> puts “Socket has been bound and configured. Waiting for packet”
> 
> #Get the packet!  
> loop do  
> msg = sock.recvfrom(100)  
> puts “Recieved Packet. Contents: “#{msg}””  
> puts “Waiting for next packet…”  
> end

You’ll much happier if you insert a Kernel#select in this loop…

---

<div class="post-metadata">

**Author:** ![clanger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dc4da7/32.png) [@clanger](https://www.ruby-forum.com/u/clanger)\
**Post date:** [March 3, 2009, 10:13am UTC](https://www.ruby-forum.com/t/sockets-and-fedora-core-9/161836/4 "2009-03-03T10:13:49Z")

</div>

Cragi Lagi wrote:

> Apologies if this is well known or I’m posting in the wrong place.

I’d say it’s probably a Linux multicast issue, and if you translate the  
Ruby code to C (which is pretty much line-for-line) you may be able to  
replicate it separately. In that case, the linux-net gurus will be able  
to help you.

> I have just spent too many hours trying to debug a problem when  
> recieving multicasts with UDPSockets… code is as follows:
> 
> SERVER=“192.0.0.1” #Real server IP removed for this post  
> RECIEVE\_ADDRESS=“0.0.0.0”  
> PORT=5001

0.0.0.0 is not a multicast address, and I’m not sure if this is a  
legitimate address to ‘join’. Perhaps try binding to the actual  
multicast address that the server is sending to? However I’m not a  
linux-net guru.

Oh, and not that it affects code operation: s/RECIEVE/RECEIVE/ 🙂

Regards,

Brian.
