From: Dave Thomas Date: 2001-05-23T12:33:28+09:00 Subject: [ruby-talk:15572] Re: detecting dead sockets? David Thiel writes: > Joel and Mathieu, thanks much for the help yesterday. > > Still working on the hello world chatserver - what I'm having a problem > with is figuring out when a user drops off, how to close their socket > gracefully. When the last user disconnects, the loop that reads input > from them starts spewing "nil". I've tried everything I can think of to > test for this(without doing something icky like if input == "nil"), but > I haven't found anything that will actually determine whether the user > is still there. Code below: > puts "connected: #{user.to_s}" > while user.socket # <------ this is what i need help with... > input = user.socket.gets How about user.socket.each do |input| # ... That'll just terminate the loop at each of file (assuming your 'socket' is an IO object). Dave