示例#1
0
        /// <summary>
        /// Tries to create a packet from the header information.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="timeStamp">The time stamp.</param>
        /// <param name="packet">The packet.</param>
        /// <returns></returns>
        internal static bool TryBuild(DJTapRecieveData data, DateTime timeStamp, out DJTapPacket packet)
        {
            DJTapHeader header = new DJTapHeader(MessageTypes.None);

            packet = header;

            try
            {
                //We have read all the data.
                if (data.EndOfData())
                {
                    data.Reset();
                    return(false);
                }

                //Check we have enough data to construct the header.
                if (data.Length - data.ReadPosition < DJTapHeader.PacketSize)
                {
                    return(false);
                }

                //Read the packet header.
                header.ReadData(data.GetReader());

                //Ensure the header packet is valid
                if (!header.IsValid())
                {
                    //Purge data as it is probably corrupted.
                    data.Reset();        //Reset position to start so we dump the data.
                    return(false);
                }

                //Read the sub packet
                switch (header.ContentType)
                {
                case MessageTypes.GWOffer:
                    packet = new GWOffer();
                    break;

                case MessageTypes.Timecode:
                    packet = new Timecode();
                    break;

                default:
                    return(false);
                }

                packet.TimeStamp = timeStamp;
                packet.ReadData(data.GetReader());
            }
            catch (EndOfStreamException)
            {
                return(false);
            }

            return(packet != null);
        }
示例#2
0
 /// <summary>
 /// Called periodically to send a GWOffer packet and advertise our prescence.
 /// </summary>
 /// <remarks>
 /// The GWOffer is sent every second/
 /// </remarks>
 /// <param name="state">The state.</param>
 private void Poll(object state)
 {
     try
     {
         GWOffer offerPacket = new GWOffer();
         offerPacket.Brand = Brand;
         offerPacket.Model = Model;
         Send(offerPacket);
     }
     catch (SocketException ex)
     {
         StopAdvertising();
         OnUnhandledException(new ApplicationException("Socket error while advertising ProDJTap, advertising will stop.", ex));
     }
     finally
     {
         if (advertTimer != null)
         {
             advertTimer.Change(1000, Timeout.Infinite);
         }
     }
 }