Esempio n. 1
0
        private void Discover(UdpClient client, IPAddress address, CancellationToken cancelationToken)
        {
            if (!IsValidClient(client.Client, address))
            {
                return;
            }

            NextSearch = DateTime.UtcNow.AddSeconds(1);
            var searchEndpoint = new IPEndPoint(address, 1900);

            foreach (var serviceType in ServiceTypes)
            {
                var datax = DiscoverDeviceMessage.Encode(serviceType, address);
                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 < 3; i++)
                {
                    if (cancelationToken.IsCancellationRequested)
                    {
                        return;
                    }
                    client.Send(data, data.Length, searchEndpoint);
                }
            }
        }
Esempio n. 2
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);
                }
            }
        }