//创建链接 public void OnMakeSession(SubscribeMsg msg) { string procotol = GetProcotolTypeFromTopic(msg.Topic); ProcotolType pt = GetProcotolType(procotol); if (ProcotolType.Invalid == pt) { // unsupported procotol return; } var sessionData = JsonHelper.SerializeJsonToObject <SessionData>(msg.Data); var key = $"{procotol}://{sessionData.target.raddr}:{sessionData.target.rport}"; if (_Sessions.ContainsKey(key)) { _Sessions[key].SendAsync(sessionData.data); //如果连接已经建立了,就只发送数据 return; } IASession session = null; if (ProcotolType.UDP == pt) { session = new UdpSession(sessionData.target); //TODO 先只处理udp协议 session.SendAsync(sessionData.data); } else if (ProcotolType.IP == pt) { session = new IpSession(sessionData.target); if (!session.Init(sessionData.target.laddr)) { return; } } _Sessions.Add(key, session); }
/// <summary> /// Begins the processing. /// </summary> protected sealed override void BeginProcessing() { Session = new IASession(Gateway, SharedSecret, certificateHash: CertificateHash, certificateValidation: CertificateValidation); base.BeginProcessing(); }