Roger P. wrote:
Were any VM’s successful?
Did you try it with BasicSocket.do_not_reverse_lookup = true?
yes
Have you tried it with linux at all? how does it work there?
now, yes
Did you try 1.9.1 on doze?
now, yes
-r
Some other test :
Linux : ok with ruby 1.8 (ubuntu 9.10 and “route add 224.0.0.0…” )
windows : ruby 1.9.1 : Nok (no receive)
(TCP/IP on ruby 1.9/windows is realy broken !)
jruby 1.4.0 : error on socket.bind
by
==========================================================
here i my test code (working file in attachement) :
Thread.abort_on_exception = true
Socket.do_not_reverse_lookup = true
class MulticastSender
def initialize(ip,port)
@ip,@port=[ip,port]
@addr = IPAddr.new(@ip).hton + IPAddr.new(“0.0.0.0”).hton
@version=0
puts “Emitter mutlticast in " + ip + “/” + port.to_s + " …”
Thread.new { loop { run ; sleep(3) } }
end
def run
@version+=1
@version = @version % 1000
socket = UDPSocket.open
#socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, [10].pack(‘i’))
max=1+rand(3)
0.upto(max) { |no|
mess = Time.now.to_f.to_s
puts "sending mc " + mess
socket.send(mess, 0, @ip , @port)
sleep(0.01)
}
ensure
socket.close rescue puts $!.to_s
end
end
class MulticastReceiver
def initialize(ip,port)
@sip,@port=[ip,port]
@version=0
host = IPAddr.new(@sip).hton + IPAddr.new(“0.0.0.0”).hton
sock = UDPSocket.new
sock.bind(Socket::INADDR_ANY, port) if isWindows()
sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, host)
sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_MULTICAST_LOOP,
“\000”) if defined?(Socket::IP_MULTICAST_LOOP)
sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_MULTICAST_TTL, 3)
if defined?(Socket::IP_MULTICAST_TTL)
sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, 3)
if defined?(Socket::IP_TTL)
sock.bind(Socket::INADDR_ANY, port) unless isWindows()
puts “Wait receiving mutlticast in " + @sip + “/” + port.to_s + " …”
Thread.new { loop { run(sock) } }
end
def run(sock)
msg, (family, port, hostname, address) = sock.recvfrom(1024)
d=Time.now
puts “MSG: from #{address} (#{hostname})/#{family} len #{msg.size} ==
#{msg.inspect }”
end
end