public void SendKcpMessage(int iepHashCode, byte[] datas) { UdpSession session = udpReceiver.GetUdpSessionMgr().FindSession(iepHashCode); if (session != null) { session.KcpSend(datas); } }
private void ProcessVerifyReqMsg(IUdpEvent evt) { UdpServerReceiver serverReceiver = evt.GetUdpReceiver() as UdpServerReceiver; if (serverReceiver == null) { return; } int iepHashCode = evt.GetIPEndPoint().GetHashCode(); UdpServerSessionMgr mgr = serverReceiver.GetUdpSessionMgr(); UdpServerSession session = mgr.FindSession(iepHashCode); if (session == null) { session = mgr.CreateSession(serverReceiver.GetSocket(), evt.GetIPEndPoint()); } else { if (!session.IsRepeatedVerify(iepHashCode)) { mgr.DelSession(iepHashCode); session = mgr.CreateSession(serverReceiver.GetSocket(), evt.GetIPEndPoint()); } } if (session == null) { Log.ErrorAf("[Udp] Verify Ok And Create Session Error"); return; } byte[] resKey = System.Text.Encoding.Default.GetBytes(KcpDef.KcpVerifyRes); MemoryStream memoryStream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(memoryStream); writer.Write(resKey); writer.Write(session.GetConv()); serverReceiver.GetUdpSender().SendUdpMsg(serverReceiver.GetSocket(), evt.GetIPEndPoint(), memoryStream.ToArray()); }
private void ProcessServerKcpMsg(IUdpEvent evt) { int iepHashCode = evt.GetIPEndPoint().GetHashCode(); UdpServerReceiver receiver = evt.GetUdpReceiver() as UdpServerReceiver; if (receiver == null) { return; } UdpServerSession session = receiver.GetUdpSessionMgr().FindSession(iepHashCode); if (session == null) { Log.WarnAf("[Udp] UdpServerReceiver ServerId = {0} Conv = {1}", receiver.GetServerId(), evt.GetConv()); } else if (evt.GetConv() == session.GetConv()) { session.KcpInput(evt.GetMessage()); } }