 
 class ClientConnection
 
+  @_connection_count : 0
+
   constructor : (@url, @id, @_on_have_session_hook, @_on_closed_permanently_hook) ->
+    @_number = ClientConnection._connection_count
+    ClientConnection._connection_count = @_number + 1
     if not @url?
       @url = DEFAULT_SERVER_WEBSOCKET_URL
     if not @id?
       @id = DEFAULT_SESSION_ID
+
+    logger.debug("Creating websocket #{@_number} to '#{@url}' session '#{@id}'")
     @socket = null
     @closed_permanently = false
     @_fragments = []


  close : () ->
    if not @closed_permanently
      @closed_permanently = true
      if @socket?
        @socket.close(1000, "close method called on ClientConnection")
      @_for_session (session) ->
        session._connection_closed()
      if @_on_closed_permanently_hook?

      @_current_handler(msg)

  _on_close : (event) ->
    logger.info("Lost websocket #{@_number} connection, #{event.code} (#{event.reason})")
    @socket = null

    if @_pending_ack?
