Ejemplo n.º 1
0
        private void Search(UdpClient client)
        {
            nextSearch = DateTime.Now.AddSeconds(SearchPeriod);
            byte[] data = DiscoverDeviceMessage.Encode();

            // 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);
            }
        }
Ejemplo n.º 2
0
        private void Search(UdpClient client)
        {
            // Sort out the time for the next search first. The spec says the
            // timeout should double after each attempt. Once it reaches 64 seconds
            // (and that attempt fails), assume no devices available
            nextSearch = DateTime.Now.AddMilliseconds(timeout);
            timeout   *= 2;

            // We've tried 9 times as per spec, try searching again in 5 minutes
            if (timeout == 128 * 1000)
            {
                timeout    = 250;
                nextSearch = DateTime.Now.AddMinutes(10);
                return;
            }

            // The nat-pmp search message. Must be sent to GatewayIP:53531
            byte[] buffer = new byte[] { PmpConstants.Version, PmpConstants.OperationCode };
            foreach (IPEndPoint gatewayEndpoint in gatewayLists[client])
            {
                client.Send(buffer, buffer.Length, gatewayEndpoint);
            }
        }