From: ts Date: 2002-11-06T01:05:02+09:00 Subject: Re: UDPSocket - bidirectional communication through one socket? >>>>> "W" == Wejn writes: W> I'm trying to write threaded application which will communicate W> (in both directions) through UDP (first thread for reading, second W> for writing). Well, probably UDP is not the best ... W> My problem is that I'm unable to get it to work ... I admit I'm not expert W> in this field, but it simply hangs on recvfrom(). The problem is that select() W> reports 'read data ready' even if there are NO data and thus it remains W> locked :( I tried to wrap it in timeout(){} block ... but the result W> is still the same ... it locks after first recvfrom(). :( How do you use ::select ? W> Is there anybody who got this to work properly? Please, speak up ... :) pigeon% cat b.rb #!/usr/bin/ruby require 'socket' $count = 4 m = Thread.new do a = UDPSocket.new a.bind('pigeon', 6666) mesg = 0 while true if IO.select([a], nil, nil, 0) p a.recvfrom(1024)[0] mesg += 1 break if mesg == $count else p "..." sleep 0.5 end end end Thread.new do b = UDPSocket.new $count.times do |i| sleep 1 b.send("hello #{i}", 0, 'pigeon', 6666) end end.join m.join pigeon% pigeon% b.rb "..." "..." "hello 0" "..." "..." "hello 1" "..." "..." "hello 2" "..." "..." "hello 3" pigeon% Guy Decoux