Пример #1
0
        private void SendInternal(IMessageTree tree)
        {
            if (_mActiveChannel != null && _mActiveChannel.Connected)
            {
                // Re-use the existing buffer.
                buf.Reset();

                _mCodec.Encode(tree, buf);

                // Nullify reference as early as possible
                tree.Message = null;

                byte[] data = buf.ToArray();

                _mActiveChannel.Client.Send(data);

                if (_mStatistics != null)
                {
                    _mStatistics.OnBytes(data.Length);
                }
            }
            else
            {
                tree.Message = null;
                Logger.Warn("SendInternal中,Socket关闭");
            }
        }
Пример #2
0
        private void SendInternal(IMessageTree tree, TcpClient activeChannel)
        {
            if (activeChannel != null && activeChannel.Connected)
            {
                var buf = new ChannelBuffer(8192);

                _codec.Encode(tree, buf);

                var data = buf.ToArray();

                activeChannel.Client.Send(data);

                _statistics?.OnBytes(data.Length);
            }
            else
            {
                Logger.Warn("SendInternal中,Socket关闭");
            }
        }
Пример #3
0
        private void SendInternal(IMessageTree tree)
        {
            if (_mLastChannel != null)
            {
                try
                {
                    Logger.Warn("SendInternal中,_mLastChannel关闭");
                    //_mLastChannel.Close();
                    _mLastChannel.Dispose();
                }
                catch
                {
                    // ignore it
                }

                _mLastChannel = null;
            }

            if (_mActiveChannel != null && _mActiveChannel.Connected)
            {
                ChannelBuffer buf = new ChannelBuffer(8192);

                _mCodec.Encode(tree, buf);

                byte[] data = buf.ToArray();

                _mActiveChannel.Client.Send(data);

                if (_mStatistics != null)
                {
                    _mStatistics.OnBytes(data.Length);
                }
            }
            else
            {
                Logger.Warn("SendInternal中,Socket关闭");
            }
        }
Пример #4
0
        private void SendInternal(IMessageTree tree)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            if (_mActiveConnection != null && _mActiveConnection.Connected)
            {
                ChannelBuffer buf = new ChannelBuffer(8192);

                _mCodec.Encode(tree, buf);

                byte[] data = buf.ToArray();

                _mActiveConnection.Client.Send(data);

                if (_mStatistics != null)
                {
                    _mStatistics.OnBytes(data.Length);
                }
            }
            else
            {
                LoggerManager.Warn("SendInternal中,Socket关闭");
            }
        }