简体   繁体   English

Android / iOS设置设备热点的IP地址

[英]Android/iOS set IP-address of device hotspot

Is there a way to "fix" or set up a static ip address of the hotspot? 有没有办法“修复”或设置热点的静态IP地址? I need to guarantee a peripheral can connect to my server socket on that ip always. 我需要保证外围设备始终可以连接到该IP上的服务器套接字。

I am trying to connect a wifi peripheral device to a server socket running on my android device. 我正在尝试将wifi外围设备连接到在我的android设备上运行的服务器套接字。 I have the peripheral connected to my android's hotspot with the ssid and ssid password. 我已使用ssid和ssid密码将外围设备连接到我的android的热点。

Right now as a work around I am using ip 192.168.43.1 . 现在,作为一种解决方法,我正在使用ip 192.168.43.1 Sources here and here say that 192.168.43.1 will is the default. 此处此处的消息源都将默认为192.168.43.1 However, I am under the impression that it's possible this ip address could change. 但是,我的印象是此IP地址可能会更改。

I am also wondering about doing this for iOS but one step at a time. 我也想在iOS上做到这一点,但一次只做一次。

Many thanks in advance! 提前谢谢了!

This IP Address is hardcoded for Android as you can see in the source . 如您在源代码中所见,此IP地址是Android的硬编码。

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. 但是,更好的实现方法是让您的外围设备获取本地网络的默认网关,因为无论热点实现如何,该默认网关都将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM