From: David Thiel Date: 2001-05-23T09:58:10+09:00 Subject: [ruby-talk:15567] detecting dead sockets? This is a multi-part message in MIME format. --------------6E14850152089FA3AA2E00FE Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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: require 'socket' require 'thread' require 'user.rb' users = [] port = 4242 server = TCPServer.new('localhost', port) while (session = server.accept) users << User.new(session) users.last.thread = Thread.new(users.last) { |user| user.linenum = users.length user.address = user.socket.addr puts "connected: #{user.to_s}" while user.socket # <------ this is what i need help with... input = user.socket.gets puts input users.each {|user| user.write(input) } end user.socket.close users.delete_at(linenum - 1) } end Thanks, David --------------6E14850152089FA3AA2E00FE Content-Type: text/x-vcard; charset=us-ascii; name="dthiel.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for David Thiel Content-Disposition: attachment; filename="dthiel.vcf" begin:vcard n:Thiel;David tel;fax:(408) 327-0333 tel;work:(408) 350-3982 x-mozilla-html:FALSE url:http://www.nexprise.com org:NexPrise, Inc.;Support adr:;;2518 Mission College Blvd.;Santa Clara;CA;95054;USA version:2.1 email;internet:dthiel@nexprise.com title:Technical Support Engineer note:Did you see my MAD SKILLZ? x-mozilla-cpt:;6080 fn:David Thiel end:vcard --------------6E14850152089FA3AA2E00FE--