/// <summary> /// Initializes a new instance of the <see cref="UdpPacket"/> class with /// information from the memory stream. /// /// Header is populated from the MemoryStream /// </summary> /// <param name="ms">The stream containing the packet and it's payload data.</param> public UdpPacket(MemoryStream ms) { Header = new UdpHeader(); try { Header.Deserialize(ms); } catch (Exception) { return; } if (this.Header.Magic != UdpHeader.MAGIC) { return; } SetPayload(ms, Header.PayloadSize); }
/// <summary> /// Initializes a new instance of the <see cref="UdpPacket"/> class with /// information from the memory stream. /// /// Header is populated from the MemoryStream /// </summary> /// <param name="ms">The stream containing the packet and it's payload data.</param> public UdpPacket(MemoryStream ms) { Header = new UdpHeader(); try { Header.Deserialize(ms); } catch (Exception) { Payload = new MemoryStream(); return; } if (this.Header.Magic != UdpHeader.MAGIC) { Payload = new MemoryStream(); return; } Payload = GetPayloadAndUpdateHeader(ms, Header.PayloadSize, Header); }