 
         @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

    constructor: (embeddedServer, callback) ->
        super({}, callback)
        @_embeddedServer = embeddedServer
        @_connect()

    write: (chunk) -> @_data(@_embeddedServer.execute(chunk))


            else
                cb new RqlDriverError "Unknown response type"
        else
            @emit 'error', new RqlDriverError "Unknown token in response"

    close: ar () ->
        @open = false
