Example #1
0
        protected override void Discover(UdpClient client, CancellationToken cancelationToken)
        {
            NextSearch = DateTime.UtcNow.AddSeconds(1);
            var searchEndpoint = new IPEndPoint(
                WellKnownConstants.IPv4MulticastAddress
                /*IPAddress.Broadcast*/
                , 1900);

            foreach (var serviceType in ServiceTypes)
            {
                var datax = DiscoverDeviceMessage.Encode(serviceType);
                var data  = Encoding.ASCII.GetBytes(datax);

                // UDP is unreliable, so send 3 requests at a time (per Upnp spec, sec 1.1.2)
                // Yes, however it works perfectly well with just 1 request.
                for (var i = 0; i < 2; i++)
                {
                    if (cancelationToken.IsCancellationRequested)
                    {
                        return;
                    }
                    client.Send(data, data.Length, searchEndpoint);
                }
            }
        }
        public void Map(IPAddress gatewayAddress)
        {
            //Get the httpu request payload
            byte[] data = DiscoverDeviceMessage.EncodeUnicast(gatewayAddress);

            Client.Send(data, data.Length, new IPEndPoint(gatewayAddress, 1900));

            new Thread(Receive).Start();
        }
        void Search(UdpClient client)
        {
            nextSearch = DateTime.Now.AddSeconds(SearchPeriod);
            byte[] data = DiscoverDeviceMessage.EncodeSSDP();

            // UDP is unreliable, so send 3 requests at a time (per Upnp spec, sec 1.1.2)
            for (int i = 0; i < 3; i++)
            {
                client.Send(data, data.Length, searchEndpoint);
            }
        }