Esempio n. 1
0
        /// <summary>
        ///     连接到远程终结点
        /// </summary>
        /// <param name="channel">基于流的通讯信道</param>
        /// <exception cref="NullReferenceException">远程终结点地址不能为空</exception>
        public void Connect(IRawTransportChannel channel)
        {
            try
            {
                #region Clear resource before.

                //get clear for org channel.
                if (_channel != null)
                {
                    _channel.Buffer        = null;
                    _channel.Disconnected -= RawChannelDisconnected;
                    _channel.ReceivedData -= RawChannelReceivedData;
                    if (_channel.IsConnected)
                    {
                        _channel.Disconnect();
                    }
                    _channel = null;
                }

                #endregion

                if (channel == null)
                {
                    throw new ArgumentNullException("channel");
                }
                channel.Connect();
                if (_connected = channel.IsConnected)
                {
                    _channel = channel;
                    if (_channel.Buffer == null)
                    {
                        _channel.Buffer = new ReceiveBuffer(102400);
                    }
                    _logicalAddress        = _channel.LogicalAddress;
                    _address               = _channel.Address;
                    _channel.Disconnected += RawChannelDisconnected;
                    _channel.ReceivedData += RawChannelReceivedData;
                    ChannelConnectedHandler(null);
                }
            }
            catch (System.Exception ex)
            {
                _tracing.Error(ex, null);
                throw;
            }
        }
Esempio n. 2
0
 /// <summary>
 ///     断开
 /// </summary>
 public void Disconnect()
 {
     if (_rawChannel != null)
     {
         _rawChannel.Disconnect();
     }
     if (_multiPacketManager != null)
     {
         _multiPacketManager.Dispose();
         _multiPacketManager = null;
     }
 }