Esempio n. 1
0
        private async Task <byte[]> RecieveStreamingPayload(int Length, OkayMessage OkayMessage)
        {
            List <byte> Data = new List <byte>(Length);

            byte[] Buffer   = new byte[Length];
            int    Recieved = 0;

            while (true)
            {
                Recieved += await Stream.ReadAsync(Buffer, 0, Buffer.Length);
                await SendMessage(OkayMessage);

                Data.AddRange(Buffer.Take(Recieved));
                if (Recieved == Length)
                {
                    break;
                }
                Buffer = new byte[Length - Recieved];
                await Task.Delay(100);
            }

            return(Data.ToArray());
        }
Esempio n. 2
0
        public async Task <T> RecieveMessage <T>(bool CheckCRC32 = true, bool StreamingPayload = false, OkayMessage OkayMessage = null) where T : Message, new()
        {
            T Message = await RecieveHeaders <T>();

            if (Message.PayloadLength > 0)
            {
                if (StreamingPayload)
                {
                    Message.Payload = await RecieveStreamingPayload(Message.PayloadLength, OkayMessage);
                }
                else
                {
                    Message.Payload = await RecieveBytes(Message.PayloadLength);

                    if (CheckCRC32)
                    {
                        if (Message.GenerateFakeCRC32(Message.Payload) != Message.FakeCRC32)
                        {
                            throw new InvalidMessageCRC32Exception();
                        }
                    }
                }
            }

            return(Message);
        }
Esempio n. 3
0
 public async Task OkayFlow(uint LocalID, uint RemoteID)
 {
     OkayMessage ReadyMessage = new OkayMessage(LocalID, RemoteID);
     await Core.SendMessage(ReadyMessage);
 }