Recently tried to let Easylink3 in hot mode connection, found that the normal broadcast address will be error, Network unreachable
Try to follow the methods on StackOverflow:
Public Static intgetcodecipaddress (wifimanager wm, Networkinfo WiFi) {wifiinfo WI=Wm.getconnectioninfo (); if(wifi.isconnected ())returnWi.getipaddress ();//normal WiFiMethod method =NULL; Try{method= Wm.getclass (). Getdeclaredmethod ("Getwifiapstate"); } Catch(nosuchmethodexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } if(Method! =NULL) method.setaccessible (true); intActualstate =-1; Try { if(method!=NULL) Actualstate= (Integer) Method.invoke (WM, (object[])NULL); } Catch(IllegalArgumentException e) {e.printstacktrace (); } Catch(illegalaccessexception e) {e.printstacktrace (); } Catch(InvocationTargetException e) {e.printstacktrace (); } if(actualstate==13) {//if WIFIAP is enabled returnConvertip2int ("192.168.43.1". GetBytes ());//hardcoded WIFIAP IP } return0; } Public Static intConvertip2int (byte[] ipAddress) { return(int) (Math.pow (3) *integer.valueof (Ipaddress[3] & 0xFF) +math.pow (2) *integer.valueof (ipaddress[2] & 0xFF ) +256*integer.valueof (Ipaddress[1] & 0xFF) +integer.valueof (Ipaddress[0] & 0xFF)); } PrivateInetAddress getbroadcastaddress (Wifimanager wm,intipAddress)throwsIOException {dhcpinfo dhcp=Wm.getdhcpinfo (); if(DHCP = =NULL) returnInetaddress.getbyname ("255.255.255.255"); intBroadcast = (ipAddress & dhcp.netmask) | ~Dhcp.netmask; byte[] Quads =New byte[4]; for(intk = 0; K < 4; k++) Quads[k]= (byte) ((Broadcast >> K * 8) & 0xFF); returninetaddress.getbyaddress (quads); }
But found that Wm.getdhcpinfo got the mask wrong, is 0
So the final broadcast address would be 255.255.255.255.
Once again, you can successfully broadcast the mask after it has been forcibly changed to 0.0.0.255
But multicasting is not going to work.
About UDP broadcasts in Android hotspot mode