/// <summary>
        /// Creates a ScoutResponsePacket given a NetworkDevice structure
        /// </summary>
        /// <param name="device"></param>
        public ScoutResponsePacket(NetworkDevice device)
        {
            PacketType = "_SCA";
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteString(device.Name);
            buffer.WriteByte((byte)device.Type);

            PacketData = buffer.ToArray();
        }
Example #2
0
        private static void ProcessReceivedScoutingInformation(ScoutResponsePacket packet)
        {
            NetworkDevice device = packet.GetNetworkDevice();

            if (device == null)
            {
                return;
            }


            NetworkDiscoveryEvent?.Invoke(null, new NetworkDiscoveryEventArgs(device));
        }
        /// <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);
        }
 public NetworkDiscoveryEventArgs(NetworkDevice _device)
 {
     device = _device;
 }