         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 
+
+    /**
+     *  @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;    
-        
+    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 
+     *  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 
+    //
+    //--------------------------------------------------------------------------
+
+    /**
+     *  Used by the streaming channels to set up the streaming connection if
      *  necessary and issue the open request to the server.
-     */ 
-    public function openStreamingConnection():void
+     *
+     *  @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(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);         
+            streamingConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, streamSecurityErrorHandler);
         }
-        
-        // Open the streaming connection, only if not already requested to open.         
+
+        // Open the streaming connection, only if not already requested to open.
         if (!streamingConnection.connected)
         {
-            var request:URLRequest = new URLRequest();      
-            request.url = channel.endpoint + "?" + COMMAND_PARAM_NAME + "=" + OPEN_COMMAND + "&" + VERSION_PARAM_NAME + "=" + VERSION_1;            
-            request.method = URLRequestMethod.POST; 
+            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);            
+            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. 
+
+    /**
+     *  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

    /**
     *  Handles IO error events dispatched by the streaming connection by
     *  re-dispatching the event for the channel.
     * 
     *  @param event The IOErrorEvent.
     */
    private function streamIoErrorHandler(event:IOErrorEvent):void
    {
		dispatchEvent(event);
    }
                    
    /**
     *  The open event is dispatched when the streaming connection has been established
     *  to the server, but it may still fail or be rejected so ignore this event and do
     *  not advance the channel to a connected state yet. 
     * 
     *  @param event The OPEN Event.
     */
    private function streamOpenHandler(event:Event):void
    {
       // Ignore. 
    }
                
    /**
     *  The arrival of data from the remote endpoint triggers progress events.
     *  The format of the data stream is HTTP Transfer-Encoding chunked, and each chunk contains either an object
     *  encoded in binary AMF format or a block of bytes to read off the network but skip any processing of.
     * 
     *  @param event The ProgressEvent. 
     */ 
    private function streamProgressHandler(event:ProgressEvent):void
    {
        if (chunkBuffer == null)


package mx.messaging.channels
{

import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.HTTPStatusEvent;
