コード例 #1
0
        /// <summary>
        /// Expect a SYN Packet which is from specific remoteIP using specific connection mode
        /// </summary>
        /// <param name="remoteIP">IP address of remote endpoint</param>
        /// <param name="mode">connection mode</param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public RdpeudpPacket ExpectSyncPacket(IPAddress remoteIP, TransportMode mode, TimeSpan timeout, out IPEndPoint remoteEndPoint)
        {
            remoteEndPoint = null;
            DateTime    endtime    = DateTime.Now + timeout;
            RDPUDP_FLAG expectFlag = RDPUDP_FLAG.RDPUDP_FLAG_SYN;

            if (mode == TransportMode.Lossy)
            {
                expectFlag |= RDPUDP_FLAG.RDPUDP_FLAG_SYNLOSSY;
            }
            while (DateTime.Now < endtime)
            {
                lock (this.unprocessedPacketBuffer)
                {
                    for (int i = 0; i < unprocessedPacketBuffer.Count; i++)
                    {
                        StackPacketInfo spInfo = unprocessedPacketBuffer[i];
                        remoteEndPoint = spInfo.remoteEndpoint as IPEndPoint;
                        if (remoteEndPoint.Address.Equals(remoteIP))
                        {
                            RdpeudpPacket eudpPacket = new RdpeudpPacket();
                            if (PduMarshaler.Unmarshal(spInfo.packet.ToBytes(), eudpPacket, false))
                            {
                                if (eudpPacket.fecHeader.uFlags.HasFlag(expectFlag))
                                {
                                    unprocessedPacketBuffer.RemoveAt(i);
                                    return(eudpPacket);
                                }
                            }
                        }
                    }
                }
                // If not receive a Packet, wait a while
                Thread.Sleep(RdpeudpSocketConfig.ReceivingInterval);
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Expect a Syn Packet
        /// </summary>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public RdpeudpPacket ExpectSynPacket(TimeSpan timeout)
        {
            if (Connected)
            {
                return(null);
            }
            DateTime endtime = DateTime.Now + timeout;

            while (DateTime.Now < endtime)
            {
                lock (unProcessedPacketBuffer)
                {
                    for (int i = 0; i < unProcessedPacketBuffer.Count; i++)
                    {
                        RdpeudpPacket eudpPacket = unProcessedPacketBuffer[i];
                        RDPUDP_FLAG   expectFlag = RDPUDP_FLAG.RDPUDP_FLAG_SYN;
                        if (this.TransMode == TransportMode.Lossy)
                        {
                            expectFlag |= RDPUDP_FLAG.RDPUDP_FLAG_SYNLOSSY;
                        }
                        if (eudpPacket.fecHeader.uFlags.HasFlag(expectFlag))
                        {
                            unProcessedPacketBuffer.RemoveAt(i);

                            // Analyse the SYN packet.
                            ProcessSynPacket(eudpPacket);

                            return(eudpPacket);
                        }
                    }
                }
                // If not receive a Packet, wait a while
                Thread.Sleep(RdpeudpSocketConfig.ReceivingInterval);
            }
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Wait for an ACK packet which meets certain conditions.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy.</param>
        /// <param name="timeout">Wait time.</param>
        /// <param name="expectAckVectors">Expected ack vectors.</param>
        /// <param name="hasFlag">Flags, which the ACK packet must contain.</param>
        /// <param name="notHasFlag">Flags, which the ACK packet must no contain.</param>
        /// <returns></returns>
        private RdpeudpPacket WaitForACKPacket(TransportMode udpTransportMode, TimeSpan timeout, AckVector[] expectAckVectors = null, RDPUDP_FLAG hasFlag = 0, RDPUDP_FLAG notHasFlag = 0)
        {
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            DateTime endTime = DateTime.Now + timeout;

            while (DateTime.Now < endTime)
            {
                RdpeudpPacket ackPacket = rdpeudpSocket.ExpectACKPacket(endTime - DateTime.Now);
                if (ackPacket != null)
                {
                    if (expectAckVectors != null)
                    {
                        if (!(ackPacket.ackVectorHeader.HasValue && CompareAckVectors(ackPacket.ackVectorHeader.Value.AckVectorElement, expectAckVectors)))
                        {
                            continue;
                        }
                    }
                    if (hasFlag != 0)
                    {
                        if ((ackPacket.fecHeader.uFlags & hasFlag) != hasFlag)
                        {
                            continue;
                        }
                    }
                    if (notHasFlag != 0)
                    {
                        if ((ackPacket.fecHeader.uFlags & notHasFlag) != 0)
                        {
                            continue;
                        }
                    }
                    return ackPacket;
                }
            }

            return null;
        }
コード例 #4
0
        /// <summary>
        /// Wait for an ACK packet which meets certain conditions.
        /// </summary>
        /// <param name="udpTransportMode">Transport mode: reliable or lossy.</param>
        /// <param name="timeout">Wait time.</param>
        /// <param name="expectAckVectors">Expected ack vectors.</param>
        /// <param name="hasFlag">Flags, which the ACK packet must contain.</param>
        /// <param name="notHasFlag">Flags, which the ACK packet must no contain.</param>
        /// <returns></returns>
        private RdpeudpPacket WaitForACKPacket(TransportMode udpTransportMode, TimeSpan timeout, AckVector[] expectAckVectors = null, RDPUDP_FLAG hasFlag = 0, RDPUDP_FLAG notHasFlag = 0)
        {
            RdpeudpSocket rdpeudpSocket = rdpeudpSocketR;
            if (udpTransportMode == TransportMode.Lossy)
            {
                rdpeudpSocket = rdpeudpSocketL;
            }

            DateTime endTime = DateTime.Now + timeout;

            while (DateTime.Now < endTime)
            {
                RdpeudpPacket ackPacket = rdpeudpSocket.ExpectACKPacket(endTime - DateTime.Now);
                if (ackPacket!=null)
                {
                    if (expectAckVectors != null)
                    {
                        if (!(ackPacket.ackVectorHeader.HasValue && CompareAckVectors(ackPacket.ackVectorHeader.Value.AckVectorElement, expectAckVectors)))
                        {
                            continue;
                        }
                    }
                    if (hasFlag != 0)
                    {
                        if ((ackPacket.fecHeader.uFlags & hasFlag) != hasFlag)
                        {
                            continue;
                        }
                    }
                    if (notHasFlag != 0)
                    {
                        if ((ackPacket.fecHeader.uFlags & notHasFlag) != 0)
                        {
                            continue;
                        }
                    }
                    return ackPacket;
                }
            }

            return null;
        }