private async Task ClientParity(OprationType ThisType, OprationType ThatType) { #if TRACE_NET Console.WriteLine($"Net:{Client.Address} {ThisType.ToString()} {ThatType.ToString()}"); Console.WriteLine($"Net:{Client.Address} Sequence:{Sequnce}"); #endif await Client.Send(new byte[] { (byte)ThisType }); await Client.Send(BitConverter.GetBytes(Sequnce)); OprationType Status = (OprationType)(await Client.Recive(1))[0]; int CurrentSequnce = BitConverter.ToInt32(await Client.Recive(4), 0); if (Status == OprationType.Exeption) { throw (await Client.RecivePacket()).Deserialize <Exception>(); } 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(); 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); } }
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(); Client.WhyDisconnect = $"Wrong Sequnce On {Address}, This side is {Sequnce}" + $" but other side is {CurrentSequnce}"; await Client.Disconncet(); throw new InvalidOperationException(Client.WhyDisconnect); } Sequnce++; if (Status != ThatType) { var Address = Client.Address.ToString(); Misstake?.Invoke(Client.Address); Client.WhyDisconnect = "Wrong opration On " + Address + ", This side is '" + ThisType.ToString() + "'" + " And other side must be '" + ThatType.ToString() + "'" + " But that is '" + Status.ToString() + "'"; await Client.Disconncet(); throw new InvalidOperationException (Client.WhyDisconnect); } }
private async Task SendParity(OprationType ThisType, OprationType ThatType) { await Socket.Send(ThisType); var Status = await Socket.Recive <OprationType>(); if (Status != ThatType) { var EX = "Wrong opration, This side is '" + ThisType.ToString() + "'" + " And other side must be '" + ThatType.ToString() + "'" + " But that is '" + Status.ToString() + "'"; throw new InvalidOperationException(EX); } }