void INodeListenerObserver.OnAcceptTcpClient(TcpClient tcpClient) { try { lock (_acceptEventSyncLock) { LogUtility.Info(string.Format("Accept a new tcp client, LEP = {0}, REP={1}.", tcpClient.Client.LocalEndPoint, tcpClient.Client.RemoteEndPoint)); SaiConnectionServer saiConnection = null; // 查找客户端的ID //uint clientID; //var clientIdFound = this.GetClientID(tcpClient.Client.RemoteEndPoint as IPEndPoint, out clientID); //if (clientIdFound) //{ // // 查找对应的SaiConnection。 // var saiID = this.BuildSaiConnectionID(_rsspConfig.LocalID, clientID); // saiConnection = this.GetSaiConnection(saiID) as SaiConnectionServer; // if (saiConnection == null) // { // saiConnection = this.CreateSaiConnectionServer(clientID); // this.AddSaiConnection(saiID, saiConnection); // saiConnection.Open(); // } //} // SaiConnection是否有效 var saiConnectionValid = saiConnection != null; // 创建一个Ale通道。 var newTunnel = new AleServerTunnel(tcpClient, this, !saiConnectionValid); if (saiConnectionValid) { saiConnection.AddAleServerTunnel(newTunnel); } else { // 加入临时链表。 _serverTunnels.Add(newTunnel); // 当临时连接个数超过规定值时,记录日志。 var count = _serverTunnels.Count; if (count > 20) { LogUtility.Warn(string.Format("临时连接的TCP个数已达到{0}个。", count)); } } // 打开。 newTunnel.Open(); } } catch (System.Exception ex) { LogUtility.Error(string.Format("{0}", ex)); } }
private void AddSaiConnection(string key, SaiConnectionServer value) { lock (_saiConnectionsLock) { _saiConnections.Add(key, value); } }
private SaiConnectionServer CreateSaiConnectionServer(uint remoteID) { var rsspEP = new RsspEndPoint(_rsspConfig.LocalID, remoteID, _rsspConfig.ApplicationType, _rsspConfig.LocalEquipType, false, _rsspConfig.SeqNoThreshold, _rsspConfig.EcInterval, _rsspConfig.AuthenticationKeys, _rsspConfig.AcceptableClients); var result = new SaiConnectionServer(rsspEP, this, this); return(result); }