From: ts Date: 2002-11-06T01:39:09+09:00 Subject: Re: UDPSocket - bidirectional communication through one socket? >>>>> "W" == Wejn writes: W> If there's no possibility to use it in the way: W> host1:X <---------------------> host2:X W> i'll have to use the (bad) model: W> host1:X ----------------------> host2:Y W> host1:Y <---------------------- host2:X W> but I'm still trying to avoid that, if possible. Well, I don't understand sorry pigeon% cat b.rb #!/usr/bin/ruby require 'socket' $count = 4 $sock = UDPSocket.new m = Thread.new do $sock.bind('pigeon', 6666) mesg = 0 while true if IO.select([$sock], nil, nil, 0) p $sock.recvfrom(1024)[0] mesg += 1 break if mesg == $count else p "..." sleep 0.5 end end end Thread.new do $count.times do |i| sleep 1 $sock.send("pigeon ==> hello #{i}", 0, 'moulon', 6666) end end.join m.join pigeon% moulon% cat b.rb #!/usr/bin/ruby require 'socket' $count = 4 $sock = UDPSocket.new m = Thread.new do $sock.bind('moulon', 6666) mesg = 0 while true if IO.select([$sock], nil, nil, 0) p $sock.recvfrom(1024)[0] mesg += 1 break if mesg == $count else p "..." sleep 0.5 end end end sleep 3 # stupid synchronisation Thread.new do $count.times do |i| sleep 1 $sock.send("moulon => hello #{i}", 0, 'pigeon', 6666) end end.join m.join moulon% moulon% b.rb "..." "..." "..." "..." "..." "..." "..." "pigeon ==> hello 0" "..." "..." "pigeon ==> hello 1" "..." "..." "pigeon ==> hello 2" "..." "..." "pigeon ==> hello 3" moulon% pigeon% b.rb "..." "..." "..." "..." "moulon => hello 0" "..." "..." "moulon => hello 1" "..." "..." "moulon => hello 2" "..." "..." "moulon => hello 3" pigeon% Guy Decoux