[ts-gen] TWEAKED: An example of multiplexing downstream using popen3() and threads
Ken Feng
kfmfe04 at gmail.com
Fri Sep 4 21:48:42 EDT 2009
Two small tweaks to the code I just posted (so the Hello World thread
doesn't get piled up behind the foobar thread).
Change mihs.rb to have no delay in response:
------------------------------------------------------------------------
#!/usr/bin/ruby
while (line=STDIN.gets)
puts line.chomp.reverse
STDOUT.flush
end
------------------------------------------------------------------------
Patch poll_from_mihs in mihs_client.rb so that it doesn't echo back
foobar responses and put in a small delay of 3 seconds for HelloWorld
reponses.
------------------------------------------------------------------------
def poll_from_mihs
while line = @stdout.gets do
puts "RESPONSE = '" + line.chomp + "'"
if ! line.include? "raboof"
sleep 3
puts_threadsafe line
end
end
end
------------------------------------------------------------------------
The output should be more interesting after this patch.
This example is just an illustration of one way to multiplex the
downstream client via Ruby.
- Ken
More information about the ts-general
mailing list