       console.log "error: ", e, evt.data
 
   onError : (evt) -> console.log "#{@kiteName}: Error #{evt.data}"
+
+  initBackoff:(options)->
+    backoff = options.backoff ? {}
+    totalReconnectAttempts = 0
+    initalDelayMs = backoff.initialDelayMs ? 700
+    multiplyFactor = backoff.multiplyFactor ? 1.4
+    maxDelayMs = backoff.maxDelayMs ? 1000 * 15 # 15 seconds
+    maxReconnectAttempts = backoff.maxReconnectAttempts ? 50
+
+    @clearBackoffTimeout =->
+      totalReconnectAttempts = 0
+
+    @setBackoffTimeout = (fn)=>
+      if totalReconnectAttempts < maxReconnectAttempts
+        timeout = Math.min initalDelayMs * Math.pow(
+          multiplyFactor, totalReconnectAttempts
+        ), maxDelayMs
+        setTimeout fn, timeout
+        totalReconnectAttempts++
+      else
+        @emit "connectionFailed"
 
   ready:(callback)->
     return KD.utils.defer callback  if @readyState

      remoteKite : @kiteName
      token      : KD.remote.getSessionToken()

    $.ajax
     type    : "POST"
     url     : "http://127.0.0.1:4000/request" #kontrol addr
     data    : JSON.stringify requestData
     success: (data, status, response) =>
       if response.status is 200
         data = JSON.parse data

         console.log "DATA", data

         console.log "Remote Kite belongs to: #{data[0].username}, type: #{data[0].kitename}"
         console.log "Addr to be connected is #{data[0].addr}"
         console.log "Token to use is #{data[0].token}"

         @token = data[0].token
         @websocket = @createWebSocket(data[0].addr)
         @registerEvents()

     error: (data, status, response) ->
       console.log "error kontrol kite request", data, status, response

  registerEvents:()->
    @websocket.onopen = (evt) => @onOpen evt
    @websocket.onclose = (evt) => @onClose evt
    @websocket.onmessage = (evt) => @onMessage evt
    @websocket.onerror = (evt) => @onError evt

  onOpen :(evt) ->
    @readyState = true
    @emit 'ready'

  onClose : (evt) -> console.log "#{@kiteName}: Disconnected"

  onMessage : (evt) ->
    try

  tell:(options, callback) ->
    @handleRequest options.method, [options, callback]

  send: (data) ->
    try
      if @readyState is READY
        @ws.send JSON.stringify data
        console.log "Sending", {data}
      else
        console.log "I'm still trying to reconnect, slow down..."
    catch e
      @disconnect()

