From: Jon Fi Date: 2006-10-02T23:46:40+09:00 Subject: Monitoring Socket Disconnect during gets or readline Hello... I am writing a simple chat program, but i have encountered a problem. I ask for a client to provide a handle, but it he disconnects during a gets call, it does weird things. [code] def get_handle(session) for attempt in (0..2) session.print "Please Login\n" response=session.gets.strip # The problem re=/(Login)\s(.+)/ md=re.match(response) response=md[2] if(!@socketHash.has_value?(response)) # This just checks to make sure the handle isn't in use. return response else session.print "Handle alerady in use... " end end end [/code] If the client disconnects at this point, ruby seems to be still waiting for a response. Also, sometimes it sends ruby's processor usage to 100%. Is there a better way to do this? Or is there a way to give gets a timeout? Thanks! -Jon -- Posted via http://www.ruby-forum.com/.