示例#1
0
        protected override bool TryParse(IpPacket packet, out IEnvelope envelope)
        {
            envelope = null;

            if (!packet.PacketHeader.DestinationIpAddress.Equals(this.ListenEndPoint.Address))
            {
                return(false);
            }

            var upacket = packet.ToUdpDatagram();

            var isValid = upacket.UdpDatagramHeader.DestinationPort == this.ListenEndPoint.Port;

            if (isValid)
            {
                envelope = new UdpEnvelope
                {
                    OccurrenceTime  = packet.ReceivedTime,
                    ReceivedTime    = packet.ReceivedTime,
                    Payload         = packet.PacketData.Array,
                    PayloadInstance = upacket,
                };
            }

            return(isValid);
        }
示例#2
0
        protected override bool TryParse(IpPacket packet, out IUdpDatagram result)
        {
            result = null;

            if (!packet.PacketHeader.DestinationIpAddress.Equals(this.ListenEndPoint.Address))
            {
                return(false);
            }

            var upacket = packet.ToUdpDatagram();

            var isValid = upacket.UdpDatagramHeader.DestinationPort == this.ListenEndPoint.Port;

            if (isValid)
            {
                result = upacket;
            }

            return(isValid);
        }