Exemple #1
0
        internal static int GetLanDNS(out MessageReplyDNSInfo dnsReply)
        {
            UdpClient client = new UdpClient();

            client.Client.ReceiveTimeout = 5000;

            MessageGetDNS getDNSMessage = new MessageGetDNS();

            byte[] data = Encoding.UTF8.GetBytes(Utility.SerializeUtility.SerializeToJsonString(getDNSMessage));

            IPEndPoint broadcastEP = new IPEndPoint(IPAddress.Broadcast, DNS_PORT);
            IPEndPoint dnsEP       = new IPEndPoint(IPAddress.Any, 0);

            int dnsCount = 0;

            client.Send(data, data.Length, broadcastEP);

            while (true)
            {
                byte[] incomingData = client.Receive(ref dnsEP);
                try
                {
                    dnsReply = Utility.SerializeUtility.DeserializeJsonString <MessageReplyDNSInfo>(Encoding.UTF8.GetString(incomingData));
                    dnsCount++;
                    if (dnsCount > 1)
                    {
                        break;
                    }
                }
                catch (Exception) { }
            }

            client.Close();

            return(dnsCount);
        }
Exemple #2
0
 private void GetDNSReceived(MessageGetDNS message, IPEndPoint remoteEndPoint)
 {
 }