Exemplo n.º 1
0
        void ITcpConnectionObserver.OnAleFrameArrival(TcpConnection theConnection, AleFrame theFrame)
        {
            try
            {
                // 只处理ConnectionRequest帧。
                if (theFrame.FrameType == AleFrameType.ConnectionRequest)
                {
                    var aleData = theFrame.UserData as AleDataConnectionRequest;
                    var key     = this.BuildAleConnectionID(aleData.MasterID, aleData.SlaveID);

                    AleConnection aleConnection;
                    if (!_aleConnections.ContainsKey(key))
                    {
                        aleConnection = new AleConnection(aleData.SlaveID, aleData.MasterID);
                        _aleConnections.GetOrAdd(key, aleConnection);
                    }
                    else
                    {
                        aleConnection = _aleConnections[key];
                    }

                    // 交给AleConnection处理。
                    ((ITcpConnectionObserver)aleConnection).OnAleFrameArrival(theConnection, theFrame);

                    // 从临时链表中移除。
                    _tcpConnections.Remove(theConnection);
                }
            }
            catch (System.Exception /*ex*/)
            {
                _tcpConnections.Remove(theConnection);
                theConnection.Close();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建一个主动方使用的ALE管理器。
        /// </summary>
        public AleManager(AleClientConfig config)
        {
            this.LocalID = config.LocalID;

            config.LinkInfo.ToList().ForEach(p =>
            {
                var key   = this.BuildAleConnectionID(config.LocalID, p.Key);
                var value = new AleConnection(config.LocalID, p.Key, p.Value);
                _aleConnections.GetOrAdd(key, value);
            });
        }