示例#1
0
        private async Task ServerParity(
            OprationType ThisType,
            OprationType ThatType)
        {
#if TRACE_NET
            Console.WriteLine($"Net:{Client.Address} {ThisType.ToString()}   {ThatType.ToString()}");
            Console.WriteLine($"Net:{Client.Address} Sequence:{Sequnce}");
#endif
            OprationType Status         = (OprationType)(await Client.Recive(1))[0];
            int          CurrentSequnce = BitConverter.ToInt32(await Client.Recive(4), 0);

            await Client.Send(new byte[] { (byte)ThisType });

            await Client.Send(BitConverter.GetBytes(Sequnce));

            if (Sequnce != CurrentSequnce)
            {
                var Address = Client.Address.ToString();
                var ex      = $"Wrong Sequnce On {Address}, This side is {Sequnce}" +
                              $" but other side is {CurrentSequnce}";
                Client.AddDebugInfo(ex);
                await Client.Disconncet();

                throw new InvalidOperationException(ex);
            }

            Sequnce++;

            if (Status != ThatType)
            {
                var Address = Client.Address.ToString();
                Misstake?.Invoke(Client.Address);
                var ex =
                    "Wrong opration On " + Address + ", This side is '" + ThisType.ToString() + "'" +
                    " And other side must be '" + ThatType.ToString() + "'" +
                    " But that is '" + Status.ToString() + "'";
                Client.AddDebugInfo(ex);
                await Client.Disconncet();

                throw new InvalidOperationException(ex);
            }
        }
示例#2
0
 private t Deserialize <t>(byte[] arrBytes)
 {
     if (IsServer)
     {
         bool IsSafe = false;
         try
         {
             var Result = arrBytes.Deserialize <t>();
             IsSafe = true;
             return(Result);
         }
         finally
         {
             if (IsSafe == false)
             {
                 Misstake?.Invoke(Client.Address);
             }
         }
     }
     else
     {
         return(arrBytes.Deserialize <t>());
     }
 }