             }            
         }
 
-		// Then, let the server know that streaming connection can be cleaned up.                         
-		if (streamingConnectionCloser == null)
-		{
-            var process:Function = function(event:Event):void
-            {		    
-                if (streamingConnectionCloser.connected) 
+		// Then, let the server know that streaming connection can be cleaned up.   
+		if (streamId != null)
+		{                      
+    		if (streamingConnectionCloser == null)
+    		{
+                var process:Function = function(event:Event):void
+                {		    
+                    if (streamingConnectionCloser.connected) 
+                    {
+                        try
+                        {
+                            streamId = null;
+                            streamingConnectionCloser.close();
+                        }
+                        catch (ignore:Error)
+                        {    
+                        }
+                    }                 
+                }
+                
+                var ignore:Function = function(event:Event):void
                 {
-                    try
-                    {
-                        streamingConnectionCloser.close();
-                    }
-                    catch (ignore:Error)
-                    {    
-                    }
-                }                 
-            }
-            
-            var ignore:Function = function(event:Event):void
-            {
-                // Simply ignore the received event.
-            }
-            
-			streamingConnectionCloser = new URLStream();                
-			streamingConnectionCloser.addEventListener(Event.COMPLETE, process);
-            streamingConnectionCloser.addEventListener(IOErrorEvent.IO_ERROR, process);			
-			// Handle these events with the complete handler, mainly to prevent
-			// them from being dispatched to the player.
-            streamingConnectionCloser.addEventListener(HTTPStatusEvent.HTTP_STATUS, ignore);
-            streamingConnectionCloser.addEventListener(SecurityErrorEvent.SECURITY_ERROR, ignore);									        			
-		} 
-		
-		// Request the streaming connection to close, only if not already requested to close.
-		if (!streamingConnectionCloser.connected)       	
-		{
-			var request:URLRequest = new URLRequest();      
-			request.url = channel.endpoint + "?" + COMMAND_PARAM_NAME + "=" + CLOSE_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; 		    
-			
-			streamingConnectionCloser.load(request);					
-		}
+                    // Ignore.
+                }
+                
+    			streamingConnectionCloser = new URLStream();                
+    			streamingConnectionCloser.addEventListener(Event.COMPLETE, process);
+                streamingConnectionCloser.addEventListener(IOErrorEvent.IO_ERROR, process);			
+    			// Ignore the following events.
+                streamingConnectionCloser.addEventListener(HTTPStatusEvent.HTTP_STATUS, ignore);
+                streamingConnectionCloser.addEventListener(SecurityErrorEvent.SECURITY_ERROR, ignore);									        			
+    		} 
+    		
+    		// Request the streaming connection close, only if not already requested to close.
+    		if (!streamingConnectionCloser.connected)       	
+    		{
+    			var request:URLRequest = new URLRequest();      
+    			request.url = channel.endpoint + "?" + COMMAND_PARAM_NAME + "=" + CLOSE_COMMAND + "&" 
+    			              + STREAM_ID_PARAM_NAME + "=" + streamId + "&" + 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; 		    
+    			
+    			streamingConnectionCloser.load(request);					
+    		}
+        }
     }
     
     //--------------------------------------------------------------------------

     *  Reference to the logger for the associated Channel.
     */
    protected var _log:ILogger;
        
    /**
     *  Storage for the hex-format chunk size value from the byte stream.

import mx.messaging.messages.AbstractMessage;
import mx.messaging.messages.CommandMessage;
import mx.messaging.messages.IMessage;
import mx.messaging.messages.AcknowledgeMessage;
    
use namespace mx_internal;    

