Forum: Ruby Sockets and Fedora Core 9

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.
4c131dd9e65845a07e4d66466ff10ed9?d=identicon&s=25 Cragi Lagi (clanger)
on 2009-03-02 23:31
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
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2009-03-03 00:16
(Received via mailing list)
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.
C1b6b5557723c9db912b075e954166d3?d=identicon&s=25 Jeff Moore (djief)
on 2009-03-03 03:13
>  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...
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2009-03-03 10:13
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.
This topic is locked and can not be replied to.