public void FindDevices(IPAddress ipAddressOfSender) { searching = true; smartPlugList = new List <SmartPlug.Core.SmartPlug>(); //Assuming to work with a class C IP address, so broadcast address looks like a.b.c.255 byte[] broadcastIpAddress = ipAddressOfSender.GetAddressBytes(); broadcastIpAddress[3] = 255; UdpClient listenClient = new UdpClient(54520); IPEndPoint localEp = new IPEndPoint(IPAddress.Any, 20560); udpState = new UdpState(localEp, listenClient); asyncCallback = new AsyncCallback(ReceiveSmartPlugCallBack); //sending a "Hello" to all smartplugs in the network SendHelloToPlugs(new IPAddress(broadcastIpAddress), udpState.UdpClient); udpState.UdpClient.BeginReceive(asyncCallback, udpState); timeout = new Timer(new TimerCallback(TimeCallBack), null, TimeoutPeriod, 0); }
public void FindDevices(IPAddress ipAddressOfSender) { searching = true; smartPlugList = new List<SmartPlug.Core.SmartPlug>(); //Assuming to work with a class C IP address, so broadcast address looks like a.b.c.255 byte[] broadcastIpAddress = ipAddressOfSender.GetAddressBytes(); broadcastIpAddress[3] = 255; UdpClient listenClient = new UdpClient(54520); IPEndPoint localEp = new IPEndPoint(IPAddress.Any, 20560); udpState = new UdpState(localEp, listenClient); asyncCallback = new AsyncCallback(ReceiveSmartPlugCallBack); //sending a "Hello" to all smartplugs in the network SendHelloToPlugs(new IPAddress(broadcastIpAddress), udpState.UdpClient); udpState.UdpClient.BeginReceive(asyncCallback, udpState); timeout = new Timer(new TimerCallback(TimeCallBack), null, TimeoutPeriod, 0); }