   constructor: (@url) ->
     # used to index subscribers
     @counter = 0 
+    @connected = false
     # subscription callbacks indexed by subscriber's ID
     @subscriptions = {};
   

    command: command
    headers: headers
    body: body
    receipt: headers.receipt?
    transaction: headers.transaction?
    destination: headers.destination?
    subscription: headers.subscription?
    error: null
    toString: ->
      lines = [command]

    client = this
    @debug?("Opening Web Socket...")
    @ws = new WebSocket(@url)
    @ws.onmessage = (evt) =>
      @debug?('<<< ' + evt.data)
      frame = Stomp.unmarshal(evt.data)
      if frame.command is "CONNECTED" and connectCallback
        @connected = true
        connectCallback(frame)
      else if frame.command is "MESSAGE"
        onreceive = @subscriptions[frame.headers.subscription]
        onreceive?(frame)
      #else if frame.command is "RECEIPT"
      #  @onreceipt?(frame)
      #else if frame.command is "ERROR"
      #  @onerror?(frame)
    @ws.onclose   = =>
      msg = "Whoops! Lost connection to " + client.url
      @debug?(msg)
      errorCallback?(msg)
    @ws.onopen    = =>
      @debug?('Web Socket Opened...')
      @_transmit("CONNECT", {login: login_, passcode: passcode_})
    @connectCallback = connectCallback
  
  disconnect: (disconnectCallback) ->
    @_transmit("DISCONNECT")
    @ws.close()
    @connected = false
    disconnectCallback?()
  
  send: (destination, headers={}, body='') ->
