From: Ben Giddings Date: 2004-06-09T23:37:47+09:00 Subject: Re: oddities with select Ara.T.Howard wrote: > why not something along the lines of this > > buf = '' > t = Thread.new{ loop{ buf << io.getc } } > sleep n_seconds > t.kill > > case buf > when %r/^$/o > raise "command not accepted" > when %r/^\s+$/o > # > # handle command > # > else > raise "bad response <#{ buf.inspect }>" > end What I'm actually using is pretty close to that: def internal_read(timeout=DEFAULT_TIMEOUT, stop_pattern=nil) retval = "" timed_out = false begin timeout(timeout) do while true if select([@sock], [], [], 0.1) retval += @sock.recv(256) if stop_pattern if retval =~ stop_pattern break end end end end end rescue Timeout::Error timed_out = true end # if timed_out # puts "Timed out" # raise # end retval end The problem is that although I've seen a newline go over the network to my PC, it is never spotted by the Ruby app, which sits there doing the 'select' forever. Your code looks slightly different, but I think it would do the exact same thing. For some reason, the newline goes over the network, but doesn't make it far enough (in 5s) that the 'select()' call sees it. Ben