From: "Firestone, Mark - Technical Support" Date: 2002-06-22T05:22:22+09:00 Subject: RE: detecting a socket dropping in multi-threaded app Thanks for your reply. I had tried doing what you described, and it never generates an exception. It just sits there. If I set abort on exception = true, then the @socket.write command before the interator generates an exception I can trap, just before the whole program abends. I tried testing for nils after the @socket.eachbyte, but that doesn't work either. I am not sure where to go from here.. ideas? I don't understand your ping idea, as the client is a telnet session. Maybe I am being thick... Thanks, Mark > -----Original Message----- > From: why@rysa.inetz.com [SMTP:why@rysa.inetz.com] > Sent: 21 June 2002 18:48 > To: ruby-talk@ruby-lang.org > 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 > NOTICE: This e-mail and any attachment(s) may contain confidential and proprietary information of Goss International Corporation and/or its subsidiaries and may be legally privileged. This e-mail is intended solely for the addressee. If you are not the addressee, dissemination, copying or other use of this e-mail or any of its content is strictly prohibited and may be unlawful. If you are not the intended recipient please inform the sender immediately and destroy the e-mail and any copies. All liability for viruses is excluded to the fullest extent permitted by law. Any views expressed in this message are those of the individual sender. No contract may be construed by this e-mail.