예제 #1
0
        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());
        }
예제 #2
0
        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());
            }
        }
예제 #3
0
 public void Start(IPEndPoint localIEP, UdpVerfiyReqDele _dele, uint _convCapacity, IUdpMsgHandler _handler, long _maxHeartBeatTime)
 {
     udpReceiver = new UdpServerReceiver(serverId, _dele, _convCapacity, _handler, _maxHeartBeatTime);
     udpReceiver.StartReceive(localIEP);
 }