title: Unusual behavior of Ruby script while working with sockets
body: <p>The thing is that I am very beginner in Ruby programming and I have some troubles with understanding  Ruby's behavior.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>require 'socket'
  
  server = TCPServer.new 2000
  loop do
    Thread.start(server.accept) do |client|
  
      puts 'Client connected: ' + client.gets
  
      line = "-1"
  
      while (line != "/close ")
        line = client.gets();
        puts line
      end
  
      puts 'client closed'
      client.close
    end
  end
  </code></pre>
  
  <p>As you see, it's a simple socket server waiting for some input information. 
  The problem is that when it gets "/close ", it exits the while loop, but never goes to 
  <code>puts 'client closed'</code> and <code>client.close</code>. So why is it so, or what am I doing wrong?</p>