Esempio n. 1
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Dns_Client()
        {
            m_pTransactions = new Dictionary<int,DNS_ClientTransaction>();

            m_pIPv4Socket = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
            m_pIPv4Socket.Bind(new IPEndPoint(IPAddress.Any,0));

            if(Socket.OSSupportsIPv6){
                m_pIPv6Socket = new Socket(AddressFamily.InterNetworkV6,SocketType.Dgram,ProtocolType.Udp);
                m_pIPv6Socket.Bind(new IPEndPoint(IPAddress.IPv6Any,0));
            }

            m_pReceivers = new List<UDP_DataReceiver>();
            m_pRandom = new Random();
            m_pCache = new DNS_ClientCache();

            // Create UDP data receivers.
            for(int i=0;i<5;i++){
                UDP_DataReceiver ipv4Receiver = new UDP_DataReceiver(m_pIPv4Socket);
                ipv4Receiver.PacketReceived += delegate(object s1,UDP_e_PacketReceived e1){
                    ProcessUdpPacket(e1);
                };
                m_pReceivers.Add(ipv4Receiver);
                ipv4Receiver.Start();

                if(m_pIPv6Socket != null){
                    UDP_DataReceiver ipv6Receiver = new UDP_DataReceiver(m_pIPv6Socket);
                    ipv6Receiver.PacketReceived += delegate(object s1,UDP_e_PacketReceived e1){
                        ProcessUdpPacket(e1);
                    };
                    m_pReceivers.Add(ipv6Receiver);
                    ipv6Receiver.Start();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Cleans up any resources being used.
        /// </summary>
        public void Dispose()
        {
            if(m_IsDisposed){
                return;
            }
            m_IsDisposed = true;

            if(m_pReceivers != null){
                foreach(UDP_DataReceiver receiver in m_pReceivers){
                    receiver.Dispose();
                }
                m_pReceivers = null;
            }

            m_pIPv4Socket.Close();
            m_pIPv4Socket = null;

            if(m_pIPv6Socket != null){
                m_pIPv6Socket.Close();
                m_pIPv6Socket = null;
            }

            m_pTransactions = null;

            m_pRandom = null;

            m_pCache.Dispose();
            m_pCache = null;
        }