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