Forum: Ruby multicast and windows

B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2009-12-09 13:42
Attachment: sim.rb (6 KB)
report for trying IP multicast with ruby 1.8 / iron ruby / jruby :

sending datagramme   :
  ok for all
receiving datagramme :
  ok for iron ruby, no reception for ruby 1.8, error with jruby

test sending datagramme :
> ruby  sim.rb s 3302  229.1.1.1  5000

test receiving datagramme :
> ruby  sim.rb r 3302  229.1.1.1  5000

NOTA

IRON RUBY:
  Socket::IP_ADD_MEMBERSHIP = 12 must be done
  Socket::IP_MULTICAST_LOOP, Socket::IP_MULTICAST_TTL not known

JRUBY :  "can't convert Fixnum into String" on socket.bind

ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
IronRuby 0.9.2.0 on .NET 2.0.0.0
jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3)
   (Java HotSpot(TM) Client VM 1.6.0_16) [x86-java]
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-12-09 21:09
Regis Siger wrote:
> report for trying IP multicast with ruby 1.8 / iron ruby / jruby :

No code?
Were any VM's successful?
Did you try it with BasicSocket.do_not_reverse_lookup = true?
-r
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2009-12-10 02:16
Roger Pack wrote:
> Regis Siger wrote:
>> report for trying IP multicast with ruby 1.8 / iron ruby / jruby :
>
> No code?
> Were any VM's successful?
> Did you try it with BasicSocket.do_not_reverse_lookup = true?
> -r

code is in sim.rb, attachment of first post
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-12-10 02:45
> code is in sim.rb, attachment of first post

Have you tried it with linux at all? how does it work there?
-r
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-12-10 02:47
> Were any VM's successful?
> Did you try it with BasicSocket.do_not_reverse_lookup = true?

Did you try 1.9.1 on doze?
-r
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2009-12-10 12:50
Attachment: test_mc.rb (3 KB)
Roger Pack 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
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2009-12-10 14:28
> Some other test :
> Linux : ok with ruby 1.8 (ubuntu 9.10 and "route add 224.0.0.0..." )

I assume Linux 1.9.x works, too, then?

> windows : ruby 1.9.1 : Nok (no receive)
>                      (TCP/IP on ruby 1.9/windows  is realy broken !)

What else is broken?
You can report bugs on redmine.ruby-lang.org

> jruby 1.4.0 : error on socket.bind

I reported a bug to them.

-r
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2010-08-06 01:57
> 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

works for me with all versions of ruby on windows... (windows 7).
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2010-08-07 02:19
(Received via mailing list)
On Thu, Dec 10, 2009 at 6:50 AM, Regis Aubarede
<regis.aubarede@gmail.com> wrote:
> jruby 1.4.0 : error on socket.bind

You should definitely try JRuby 1.5.1. There were hundreds of bug
fixes, including many for sockets.

- Charlie
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.