Search code examples
androidiosip-addressserversockethotspot

Android/iOS set IP-address of device hotspot


Is there a way to "fix" or set up a static ip address of the hotspot? I need to guarantee a peripheral can connect to my server socket on that ip always.

I am trying to connect a wifi peripheral device to a server socket running on my android device. I have the peripheral connected to my android's hotspot with the ssid and ssid password.

Right now as a work around I am using ip 192.168.43.1. Sources here and here say that 192.168.43.1 will is the default. However, I am under the impression that it's possible this ip address could change.

I am also wondering about doing this for iOS but one step at a time.

Many thanks in advance!


Solution

  • This IP Address is hardcoded for Android as you can see in the source.

    if (ifcg != null) {
        /* IP/netmask: 192.168.43.1/255.255.255.0 */
        ifcg.setLinkAddress(new LinkAddress(
            NetworkUtils.numericToInetAddress("192.168.43.1"), 24));
        ifcg.setInterfaceUp();
        mNwService.setInterfaceConfig(intf, ifcg);
    }
    

    However a better implementation is for your peripheral device to get the default gateway of the local network as that will work regardless of hotspot implementation.