David Thiel <dthiel / nexprise.com> 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