ENDA.PLCNetLib.Finder.ReceiveCallback C# (CSharp) Method

ReceiveCallback() private method

private ReceiveCallback ( IAsyncResult ar ) : void
ar IAsyncResult
return void
        private void ReceiveCallback(IAsyncResult ar)
        {
            UdpClient client = (UdpClient)ar.AsyncState;
            byte[] data;
            try
            {
                data = client.EndReceive(ar, ref m_remoteEP);
                if (data.Length < 6)
                {
                    client.BeginReceive(new AsyncCallback(ReceiveCallback), client);
                    return;
                }
                BinaryReader br = new BinaryReader(new MemoryStream(data));
                String str = String.Empty;
                for (int i = 0; i < 6; i++)
                    str += Convert.ToString(br.ReadByte(), 16).PadLeft(2, '0') + ":";
                str = str.Substring(0, str.Length - 1);
                if (data.Length > 6)
                {
                    byte proto = br.ReadByte();
                    if (proto == 2)
                    {
                        int rev = br.ReadInt32();
                        //string label = br.ReadString();
                    }
                }
                if (!m_dict.ContainsKey(str) || !m_dict[str].Equals(m_remoteEP.Address))
                {
                    m_dict[str] = m_remoteEP.Address;
                    if (DeviceFound != null)
                        DeviceFound(str, m_dict[str]);
                }
                client.BeginReceive(new AsyncCallback(ReceiveCallback), client);
            }
            catch (ObjectDisposedException e)
            {
            }
        }