Sockets and Fedora Core 9

Discussion in 'Ruby' started by Cragi Lagi, Mar 2, 2009.

  1. Cragi Lagi

    Cragi Lagi Guest

    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
    --
    Posted via http://www.ruby-forum.com/.
     
    Cragi Lagi, Mar 2, 2009
    #1
    1. Advertising

  2. Cragi Lagi

    Jeff Moore Guest

    > 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...


    --
    Posted via http://www.ruby-forum.com/.
     
    Jeff Moore, Mar 3, 2009
    #2
    1. Advertising

  3. 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.
    --
    Posted via http://www.ruby-forum.com/.
     
    Brian Candler, Mar 3, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Trent

    JAR help in FEDORA CORE 2

    Trent, May 27, 2004, in forum: Java
    Replies:
    1
    Views:
    421
    David Lesaffre
    May 28, 2004
  2. AnonymousFC4
    Replies:
    7
    Views:
    2,391
    Jon Martin Solaas
    Aug 9, 2005
  3. Thomas
    Replies:
    1
    Views:
    403
    Rob Renaud
    Nov 19, 2003
  4. sudhir
    Replies:
    0
    Views:
    350
    sudhir
    Mar 8, 2006
  5. Ed Redman

    fedora core 5 and tcltklib

    Ed Redman, Aug 10, 2006, in forum: Ruby
    Replies:
    0
    Views:
    94
    Ed Redman
    Aug 10, 2006
Loading...

Share This Page