require 'socket' gs = TCPServer.open(0) socks = [gs] addr = gs.addr addr.shift puts "server is on #{addr.join(':')}" while true nsock = select(socks) next if nsock == nil for s in nsock[0] if s == gs socks.push(s.accept) puts "#{s} is accepted" else if s.eof? puts "#{s} is gone" s.close socks.delete(s) else str = s.gets s.write(str) end end end end