#! /usr/bin/ruby
require 'socket'                

# Socket to listen on port 2000
server = TCPServer.open(2000)


#loop do: Servers run forever
loop do                          
  Thread.start(server.accept) do |client|
  input = client.recv(100)
   
  #cutting off /n character 
  input = input[0, input.length-1] 
  
  #converting input into downcase
  input = input.downcase 
  case input
    when "exit"
      Thread.kill self
    
    #Send the time to the client  
    when "time"
      client.puts(Time.now.ctime)   
    when "food"
      client.puts "Pommes"
    when "drink"
      client.puts "coffee"
    else
      client.puts "I don't understand this"
    end
#client.close                  # Disconnect from the client
  end
end
