 	 *  @return Returns the message that was read.
 	 */
     protected function readMessage():IMessage
-    {    	
-    	return null;                	    	
-    }
-    
+    {
+    	return null;
+    }
+
     //--------------------------------------------------------------------------
     //
     // Private Methods
-    // 
-    //--------------------------------------------------------------------------
-
-    /**
-     *  Helper method to process the chunk size value in hex read from the beginning of a chunk 
+    //
+    //--------------------------------------------------------------------------
+
+    /**
+     *  Helper method to process the chunk size value in hex read from the beginning of a chunk
      *  into a decimal value that can be used to determine when all data for the chunk has been read.
-     * 
+     *
      *  @param value The hex value as a String.
      *  @return The hex value converted as a decimal int.
      */
     private function convertHexToDecimal(value:String):int
     {
         var result:int = 0;
-        var powerOfSixteen:int = 0; 
+        var powerOfSixteen:int = 0;
         for (var i:int = value.length - 1; i >= 0; i--)
         {
             if (powerOfSixteen == 0)
                 powerOfSixteen = 1;
-            else    
+            else
                 powerOfSixteen *= 16;
-            
+
             var digit:int = HEX_VALUES[value.charAt(i)];
             result += digit * powerOfSixteen;
         }
         return result;
-    }   
-    
-    /**
-     *  Handles a complete event that indicates that the streaming connection 
+    }
+
+    /**
+     *  Handles a complete event that indicates that the streaming connection
      *  has been closed by the server by re-dispatching the event for the channel.
-     * 
+     *
      *  @param event The COMPLETE Event.
      */
     private function streamCompleteHandler(event:Event):void
     {
     	dispatchEvent(event);
     }
-     
+
     /**
      *  Handles HTTP status events dispatched by the streaming connection by
      *  re-dispatching the event for the channel.
-     * 
+     *
      *  @param event The HTTPStatusEvent.
      */
     private function streamHttpStatusHandler(event:HTTPStatusEvent):void

                            {
							    channel.dispatchEvent(MessageEvent.createEvent(MessageEvent.MESSAGE, message));
                            }
                        } 
						state = RESET_BUFFER_STATE; 	                                              
                    }
                    else // Wait for the rest of the chunk to arrive.
                    {

        super();
    	this.channel = channel;
    	this._log = log;
    }

    //--------------------------------------------------------------------------
    //
    // Variables
    //
    //--------------------------------------------------------------------------

  	/**
  	 * The Channel that uses this class.
  	 */
  	 protected var channel:Channel;

    /**
     *  Byte buffer used to store the current chunk from the remote endpoint.
     *  Once a full chunk has been buffered, a message instance encoded in binary
     *  AMF format can be read from the chunk and dispatched.
     */
    protected var chunkBuffer:ByteArray;

    /**
     *  Counter that keeps track of how many data bytes remain to be read for the current chunk.
     *  A sentinal value of -1 indicates an initial state (either waiting for the first chunk or
     *  just finished parsing the previous chunk).
     */
    protected var dataBytesToRead:int = -1;

    /**
     *  Index into the chunk buffer pointing to the first byte of chunk data.
     */
    protected var dataOffset:int;

    /**
     *  @private
     *  Reference to the logger for the associated Channel.
     */
    protected var _log:ILogger;

    /**
     *  @private
     *  The server-assigned id for the streaming connection.
     */
    protected var streamId:String;

    /**
     *  Storage for the hex-format chunk size value from the byte stream.
     */
    private var hexChunkSize:String;

    /**
     *  Current parse state on the streaming connection.
     */
    private var state:int = INIT_STATE;

    /**
     *  URLStream used to open a streaming connection from the server to
     *  the client over HTTP.
     */
    private var streamingConnection:URLStream;

    /**
     *  URLStream used to close the original streaming connection opened from
     *  the server to the client over HTTP.
     */
	private var streamingConnectionCloser:URLStream;

    //--------------------------------------------------------------------------
    //
    // Public Methods
    //
    //--------------------------------------------------------------------------

    /**
     *  Used by the streaming channels to set up the streaming connection if
     *  necessary and issue the open request to the server.
     *
     *  @param appendToURL The string to append such as session id to the endpoint
     *  url while making the streaming connection request.
     */
    public function openStreamingConnection(appendToURL:String=null):void
    {
    	// Construct the streaming connection if needed.
        if (streamingConnection == null)
        {
            streamingConnection = new URLStream();
            streamingConnection.addEventListener(Event.OPEN, streamOpenHandler);
            streamingConnection.addEventListener(ProgressEvent.PROGRESS, streamProgressHandler);
            streamingConnection.addEventListener(Event.COMPLETE, streamCompleteHandler);
            streamingConnection.addEventListener(HTTPStatusEvent.HTTP_STATUS, streamHttpStatusHandler);
            streamingConnection.addEventListener(IOErrorEvent.IO_ERROR, streamIoErrorHandler);
            streamingConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, streamSecurityErrorHandler);
        }

        // Open the streaming connection, only if not already requested to open.
        if (!streamingConnection.connected)
        {
            var request:URLRequest = new URLRequest();
            var url:String = channel.endpoint;
            if (appendToURL != null)
                url += appendToURL;
            request.url = url + "?" + COMMAND_PARAM_NAME + "=" + OPEN_COMMAND + "&" + VERSION_PARAM_NAME + "=" + VERSION_1;
            request.method = URLRequestMethod.POST;
            var postParams:URLVariables = new URLVariables();
            postParams[AbstractMessage.FLEX_CLIENT_ID_HEADER] = FlexClient.getInstance().id
            request.data = postParams;

			streamingConnection.load(request);
        }
    }

    /**
     *  Used by the streaming channels to shut down the streaming connection.
     */
    public function closeStreamingConnection():void
    {
    	// First, close the existing connection.
        if (streamingConnection != null)
        {
            if (streamingConnection.connected)
            {
                try
