From: Dylan Lukes Date: 2009-11-21T00:12:48+09:00 Subject: select only taking alternating values? The problem in question seems to be that only every OTHER line of terminal input is handled by elsif input == STDIN. Here is the complete code, with some masked stuff Code: require 'socket' require 'protocol.rb' #Settings for the server we're connecting too class AmityClient include AmityPackets def initialize #Bool to check if we've received a Ctrl-C, so we can shut down and clean up nicely. @interrupted = false @hostname = "MASKED" @port = 6002 @username = "amity" @mppass = "MASKED" begin puts "Trying to connect to #{@hostname} on #{@port}" @sock = TCPSocket.new(@hostname, @port) sendLogin(@sock, @username, @mppass) sendChat(@sock, "-- Amity b0.1 connected --") run() rescue IOError puts "-- Socket closed --" rescue puts "Error: #{$!}" end end def run while 1 #Enter Infinite Loop #Trap a Ctrl-C, and turn on interrupted trap("INT") {@interrupted = true} #select input results = select([@sock, STDIN], nil, nil) if results != nil then for input in results[0] if input == @sock then #Socket Input found #Socket stuff here elsif input == STDIN #Standard Input found if gets.chomp! == "!quit" then cleanupAndExit else puts gets.chomp! end end #if end #for end #if if @interrupted puts "\nInterrupted! Cleaning up..." cleanupAndExit end end #while end #def def cleanupAndExit @sock.close sendChat(@sock, "User quit Amity Client") exit end end interrupted = false trap("INT") {interrupted = true} amity = AmityClient.new if interrupted puts "Interrupted" exit end -- Posted via http://www.ruby-forum.com/.