Sockets and Fedora Core 9

C

Cragi Lagi

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
 
J

Jeff Moore

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

Brian Candler

Cragi said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top