About UDP broadcasts in Android hotspot mode

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.