def mainloop
  SOCKET_TIMEOUT = 0.2
  RECONNECT_WAIT = 5
 
  while true
    connect

    while true
      if @socket.select SOCKET_TIMEOUT
        break unless reply = @socket.gets
        @client.process reply
      end

      @timer.tick
    end

    puts "disconnected"
    @channels.clear

    puts "waiting to reconnect"
    sleep RECONNECT_WAIT
  end
end

