ReadBytes() public method

public ReadBytes ( int len ) : byte[]
len int
return byte[]
        private async Task HandshakeOld(RTMPBinaryReader c1reader, CancellationToken cancel_token)
        {
            var s1vec = new byte[1528];
            var rand  = new Random();

            rand.NextBytes(s1vec);
            await SendAsync(writer => {
                writer.Write(0);
                writer.Write(0);
                writer.Write(s1vec);
            }, cancel_token).ConfigureAwait(false);

            var c1time = c1reader.ReadInt32();
            var c1ver  = c1reader.ReadInt32();
            var c1vec  = c1reader.ReadBytes(1528);

            await SendAsync(writer => {
                writer.Write(c1time);
                writer.Write(c1ver);
                writer.Write(c1vec);
            }, cancel_token).ConfigureAwait(false);

            using (var reader = await RecvAsync(1536, cancel_token).ConfigureAwait(false)) {
                var c2time = reader.ReadInt32();
                var c2zero = reader.ReadInt32();
                var c2vec  = reader.ReadBytes(1528);
                if (!s1vec.SequenceEqual(c2vec))
                {
                    throw new InvalidDataException("C2 random vector is not matched.");
                }
            }
        }
示例#2
0
        public AggregateMessage(RTMPMessage x)
            : base(x)
        {
            var messages = new List <RTMPMessage>();

            using (var reader = new RTMPBinaryReader(new MemoryStream(x.Body))) {
                while (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    var message_type = (RTMPMessageType)reader.ReadByte();
                    var length       = reader.ReadUInt24();
                    var timestamp    = reader.ReadUInt32();
                    var stream_id    = reader.ReadUInt24();
                    var body         = reader.ReadBytes(length);
                    var msg          = new RTMPMessage(
                        message_type,
                        timestamp + x.Timestamp,
                        x.StreamId,
                        body);
                    var prevlen = reader.ReadUInt32();
                    if (prevlen == body.Length + 11)
                    {
                        messages.Add(msg);
                    }
                }
            }
        }
示例#3
0
 public UserControlMessage(RTMPMessage x)
     : base(x)
 {
     using (var reader = new RTMPBinaryReader(new MemoryStream(x.Body))) {
         UserControlMessageType    = (UserControlMessageType)reader.ReadUInt16();
         UserControlMessagePayload = reader.ReadBytes(x.Body.Length - 2);
     }
 }
示例#4
0
        private bool Handshake()
        {
            Logger.Debug("Handshake start");
            var rand = new Random();
            var c0   = Recv(1);

            Send(new byte[] { 0x03 });
            var s1vec = new byte[1528];

            rand.NextBytes(s1vec);
            Send(s => {
                using (var writer = new RTMPBinaryWriter(s)) {
                    writer.Write(0);
                    writer.Write(0);
                    writer.Write(s1vec);
                }
            });
            using (var reader = new RTMPBinaryReader(new MemoryStream(Recv(1536)))) {
                Send(s => {
                    using (var writer = new RTMPBinaryWriter(s)) {
                        writer.Write(reader.ReadInt32());
                        writer.Write(reader.ReadInt32());
                        writer.Write(reader.ReadBytes(1528));
                    }
                });
            }
            using (var reader = new RTMPBinaryReader(new MemoryStream(Recv(1536)))) {
                reader.ReadInt32();
                reader.ReadInt32();
                if (!s1vec.Equals(reader.ReadBytes(1528)))
                {
                    Logger.Debug("Handshake failed");
                    return(false);
                }
            }
            timer.Reset();
            timer.Start();
            Logger.Debug("Handshake succeeded");
            return(true);
        }
        private async Task HandshakeNew(RTMPBinaryReader c1reader, CancellationToken cancel_token)
        {
            var s1   = new byte[1536];
            var rand = new Random();

            rand.NextBytes(s1);
            //timestamp
            s1[0] = s1[1] = s1[2] = s1[3] = 0;
            //version
            s1[4] = 3;
            s1[5] = 5;
            s1[6] = 1;
            s1[7] = 1;
            s1    = SetServerHandshakeDigest1(s1, DigestPosition.First);
            await SendAsync(s1, cancel_token).ConfigureAwait(false);

            var c1    = c1reader.ReadBytes(1536);
            var c1pos = ValidateClientHandshakeDigest1(c1);

            if (c1pos == DigestPosition.Unknown)
            {
                throw new InvalidDataException("C1 digest is not matched.");
            }

            var s2 = SetServerHandshakeDigest2(c1, c1pos);

            await SendAsync(s2, cancel_token).ConfigureAwait(false);

            using (var c2reader = await RecvAsync(1536, cancel_token).ConfigureAwait(false)) {
                var c2 = c2reader.ReadBytes(1536);
                if (!ValidateClientHandshakeDigest2(c2, s1, DigestPosition.First))
                {
                    throw new InvalidDataException("C2 digest is not matched.");
                }
            }
        }
示例#6
0
 public UserControlMessage(RTMPMessage x)
     : base(x)
 {
     using (var reader=new RTMPBinaryReader(new MemoryStream(x.Body))) {
     UserControlMessageType = (UserControlMessageType)reader.ReadUInt16();
     UserControlMessagePayload = reader.ReadBytes(x.Body.Length-2);
       }
 }
示例#7
0
 public AggregateMessage(RTMPMessage x)
     : base(x)
 {
     var messages = new List<RTMPMessage>();
       using (var reader=new RTMPBinaryReader(new MemoryStream(x.Body))) {
     while (reader.BaseStream.Position<reader.BaseStream.Length) {
       var message_type = (RTMPMessageType)reader.ReadByte();
       var length       = reader.ReadUInt24();
       var timestamp    = reader.ReadUInt32();
       var stream_id    = reader.ReadUInt24();
       var body         = reader.ReadBytes(length);
       var msg = new RTMPMessage(
     message_type,
     timestamp + x.Timestamp,
     x.StreamId,
     body);
       var prevlen = reader.ReadUInt32();
       if (prevlen==body.Length+11) {
     messages.Add(msg);
       }
     }
       }
 }
示例#8
0
		private async Task HandshakeOld(RTMPBinaryReader c1reader, CancellationToken cancel_token)
		{
			var s1vec = new byte[1528];
			var rand = new Random();
			rand.NextBytes(s1vec);
			await Send(writer => {
				writer.Write(0);
				writer.Write(0);
				writer.Write(s1vec);
			}, cancel_token);

			var c1time = c1reader.ReadInt32();
			var c1ver  = c1reader.ReadInt32();
			var c1vec  = c1reader.ReadBytes(1528);
			await Send(writer => {
				writer.Write(c1time);
				writer.Write(c1ver);
				writer.Write(c1vec);
			}, cancel_token);

			await Recv(1536, reader => {
				var c2time = reader.ReadInt32();
				var c2zero = reader.ReadInt32();
				var c2vec = reader.ReadBytes(1528);
				if (!s1vec.SequenceEqual(c2vec)) {
					throw new InvalidDataException("C2 random vector is not matched.");
				}
			}, cancel_token);
		}
示例#9
0
		private async Task HandshakeNew(RTMPBinaryReader c1reader, CancellationToken cancel_token)
		{
			var s1 = new byte[1536];
			var rand = new Random();
			rand.NextBytes(s1);
			//timestamp
			s1[0] = s1[1] = s1[2] = s1[3] = 0;
			//version
			s1[4] = 3;
			s1[5] = 5;
			s1[6] = 1;
			s1[7] = 1;
			s1 = SetServerHandshakeDigest1(s1, DigestPosition.First);
			await Send(s1, cancel_token);

			var c1 = c1reader.ReadBytes(1536);
			var c1pos = ValidateClientHandshakeDigest1(c1);
			if (c1pos==DigestPosition.Unknown) {
				throw new InvalidDataException("C1 digest is not matched.");
			}

			var s2 = SetServerHandshakeDigest2(c1, c1pos);
			await Send(s2, cancel_token);

			var c2reader = await Recv(1536, cancel_token);
			var c2 = c2reader.ReadBytes(1536);
			if (!ValidateClientHandshakeDigest2(c2, s1, DigestPosition.First)) {
				throw new InvalidDataException("C2 digest is not matched.");
			}
		}
 private bool Handshake()
 {
     Logger.Debug("Handshake start");
       var rand = new Random();
       var c0 = Recv(1);
       Send(new byte[] { 0x03 });
       var s1vec = new byte[1528];
       rand.NextBytes(s1vec);
       Send(s => {
     using (var writer=new RTMPBinaryWriter(s)) {
       writer.Write(0);
       writer.Write(0);
       writer.Write(s1vec);
     }
       });
       using (var reader=new RTMPBinaryReader(new MemoryStream(Recv(1536)))) {
     Send(s => {
       using (var writer=new RTMPBinaryWriter(s)) {
     writer.Write(reader.ReadInt32());
     writer.Write(reader.ReadInt32());
     writer.Write(reader.ReadBytes(1528));
       }
     });
       }
       using (var reader=new RTMPBinaryReader(new MemoryStream(Recv(1536)))) {
     reader.ReadInt32();
     reader.ReadInt32();
     if (!s1vec.Equals(reader.ReadBytes(1528))) {
       Logger.Debug("Handshake failed");
       return false;
     }
       }
       timer.Reset();
       timer.Start();
       Logger.Debug("Handshake succeeded");
       return true;
 }