/// <summary>
        /// Deserializes a data buffer into a ScoutResponsePacket
        /// </summary>
        /// <param name="data"></param>
        /// <param name="endPoint"></param>
        public ScoutResponsePacket(byte[] data, IPEndPoint endPoint)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(data);
            PacketType     = Encoding.Default.GetString(buffer.ReadBytes(4));
            PacketData     = new byte[data.Length - 4];
            PacketEndPoint = endPoint;
            Array.Copy(data, 4, PacketData, 0, PacketData.Length);
            buffer.Dispose();
        }
        /// <summary>
        /// Returns a NetworkDevice object containing the information included in the packet.
        /// </summary>
        /// <returns></returns>
        public NetworkDevice GetNetworkDevice()
        {
            // The packet data needs to be at least 6 bytes long. Strings in the packetbuffer class are saved with a
            // 4-bytes integer for the lenght, and then the string itself
            if (PacketData == null || PacketData.Length < 6)
            {
                return(null);
            }

            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(PacketData);

            NetworkDevice device = new NetworkDevice();

            device.Name     = buffer.ReadString();
            device.Type     = (NetworkDeviceType)buffer.ReadByte();
            device.EndPoint = PacketEndPoint;
            buffer.Dispose();

            return(device);
        }
Beispiel #3
0
        /// <summary>
        /// Returns a FileStructure object containing the information
        /// </summary>
        /// <returns></returns>
        public LocalFileStructure GetFileStructure()
        {
            if (PacketData == null || PacketData.Length < 12)
            {
                return(null);
            }

            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(PacketData);

            LocalFileStructure fStruct = new LocalFileStructure();

            buffer.ReadInteger(); // Ignore the local ID
            fStruct.FileSize      = buffer.ReadLong();
            fStruct.FileName      = buffer.ReadString();
            fStruct.FileExtension = buffer.ReadString();
            fStruct.FullName      = fStruct.FileName + fStruct.FileExtension;

            buffer.Dispose();

            return(fStruct);
        }