public override void Write(RtmpPacket packet)
        {
            _lock.AcquireReaderLock();
            try
            {
                if (IsClosed || IsClosing || IsDisconnecting)
                {
                    return; // Already shutting down.
                }
            }
            finally
            {
                _lock.ReleaseReaderLock();
            }
            if (log.IsDebugEnabled)
            {
                log.Debug(__Res.GetString(__Res.Rtmp_WritePacket, _connectionId, packet));
            }

            if (!this.IsTunneled)
            {
                //encode
                WritingMessage(packet);
                ByteBuffer outputStream = null;
                _lock.AcquireWriterLock();
                try
                {
                    outputStream = RtmpProtocolEncoder.Encode(this.Context, packet);
                }
                finally
                {
                    _lock.ReleaseWriterLock();
                }
                Write(outputStream);
                _rtmpServer.RtmpHandler.MessageSent(this, packet);
            }
            else
            {
                //We should never get here
                System.Diagnostics.Debug.Assert(false);
            }
        }
 public override void Write(RtmpPacket packet)
 {
     if (!base.IsDisposed && this.IsActive)
     {
         if (log.get_IsDebugEnabled())
         {
             log.Debug("Write " + packet.Header);
         }
         if (!this.IsTunneled)
         {
             this.WritingMessage(packet);
             ByteBuffer buf = RtmpProtocolEncoder.Encode(base.Context, packet);
             this.Send(buf);
             this._rtmpServer.RtmpHandler.MessageSent(this, packet);
         }
         else
         {
             Debug.Assert(false);
         }
     }
 }