From: why@... Date: 2002-06-22T02:48:05+09:00 Subject: Re: detecting a socket dropping in multi-threaded app Firestone, Mark - Technical Support (mark.firestone@gossgraphic.co.uk) wrote: > I'm still working on my Ruby BBS project. I need to be able to run some > code when a user drops offline without logging off. Right now, Ruby is just > killing the thread. I need to know how to make it pass an exception (or > something) back to the main loop so the main loop can take the user out of > the online user database. I've tried testing for nil and raising an > exception, but it doesn't seem to work. Help please!! You guys never let me > down. > > thanks in advance! > > Mark First, I don't see any begin..rescue around your TCPSocket#each_byte: begin @sock.each_byte do |fred| # Process bytes sent end rescue # Handle exception here.. end I find the surest way of finding a disconnect is to implement a simple PING request from the server to the client. It looks like your byte commands could include a PING response from the client. I just run a separate thread that periodically checks that the PING count is climbing.. Then, set Thread#abort_on_exception = false so you can make sure that only clients that don't return pings get killed. If you go this route, then don't forget to use a mutex. -- Jonathan Gillette iNetZ Media