 
         @buffer = new ArrayBuffer 0
 
-        @_connect = =>
+        @_events = {}
+
+        errCallback =  =>
+            callback new RqlDriverError "Could not connect to #{@host}:#{@port}."
+
+        @on 'error', errCallback
+
+        @on 'connect', =>
             @open = true
-            @_error = => # Clear failed to connect callback
+            @removeListener 'error', errCallback
             callback null, @
-
-        @_error = => callback new RqlDriverError "Could not connect to #{@host}:#{@port}."
 
     _data: (buf) ->
         # Buffer data, execute return results if need be

            else
                cb new RqlDriverError "Unknown response type"
        else
            @_error new RqlDriverError "Unknown token in response"

    close: ar () ->
        @open = false

                if xhr.status is 200
                    @_url = url
                    @_connId = (new DataView xhr.response).getInt32(0, true)
                    @emit 'connect'
                else
                    @emit 'error', new RqlDriverError "XHR error, http status #{xhr.status}."
        xhr.send()

    cancel: ->
