0

UPDATE: The hotspot created on oreo and below has static IP which is 192.168.43.1. This is a change in Android 9 and above. and i want to do it for Android 9. I need to run ServerSocket on a static IP address. My scenario is that i need to access my Server which is running on an Android and the server android device has its own WifiHotSpot without internet connectivity. The clients will be connected to the server only when they are connected to that hotspot. I cant seem to find a way to communicate my SERVERSOCKET IP address to the clients as i cant display it on the screen(The screen won't be visible to the user- Special USE CASE). Thats why i need a static IP to run ServerSocket but can't seem to run it as if i give it any IP lets say 192.168.43.180 it gives exception EADDRESSNOTAVAIL address not available. Any help is much appreciated.

SocketAddress socketAddress = new InetSocketAddress("192.168.43.128",2041);
   httpServerSocket = new ServerSocket();
   httpServerSocket.bind(socketAddress);
  • I think this will help you https://stackoverflow.com/questions/32487467/how-to-connect-sockets-using-static-ip-java – Jignesh Mayani Feb 26 '20 at 07:37
  • This may help you. https://codevog.com/blog/2015-06-03-jmdns-java-multicast-dns-using-in-android – Komal Feb 26 '20 at 07:44
  • Do not bind the server socket to an address. That is not needed. Only start it listening on a port. A server socket does not care for an ip address. The device has an ip address. You have to tell that the clients. An Android hotspot has always the same ip i think. – blackapps Feb 26 '20 at 08:02
  • `I cant seem to find a way to communicate my SERVERSOCKET IP address to the clients` No. The clients should know the ip of the device. Of the hotspot. But they know it as soon as the client device is connected to the hotspot. – blackapps Feb 26 '20 at 08:05
  • You dont need an extra static ip address as the hotspot will always have the same ip. Didnt you perceive that? – blackapps Feb 26 '20 at 08:08
  • @blackapps its not for one device. Its use case is for many unique devices and those IPS are definitely not same. Infact each time hotspot is turned off/On the Ip is changed – Owais Nizam Feb 26 '20 at 10:02
  • 1
    @Komal thanks but we don't want another app. We just want the user to hit a URL in browser using any client and an HTML page should be served. Whether its an IPHONE user from safari, laptop or android. They just need to be connected to the HOTSPOT – Owais Nizam Feb 26 '20 at 10:07
  • 1
    @SilverskyTechnology I am using running android 9 img on OrangePi board. and first time when it'll be turned on there will be no internet connection. I want all of this as local. – Owais Nizam Feb 26 '20 at 10:11
  • `. Infact each time hotspot is turned off/On the Ip is changed` But then what you ask is unrealistic. A server socket cannot change an ip address of the device where it is running on. You have to go to the settings of your device. To the settings of the hotspot and let it use a fixed ip. And it is hard to believe that the ip is different every time. – blackapps Feb 26 '20 at 10:19
  • On a 'normal' Android device the ip of the hotspot is always 192.168.43.1. – blackapps Feb 26 '20 at 10:26
  • `as if i give it any IP lets say 192.168.43.180` That would be the ip of a client then. You will not use a clients ip to connect to a server on a hotspot. – blackapps Feb 26 '20 at 10:28
  • @blackapps yes on a normal Android device it is. but as i mentioned i am running android image on OrangePi board and it is behaving like this. – Owais Nizam Feb 26 '20 at 10:36
  • @blackapps just checked till android 8 (oreo) the hotspot address is 192.168.43.1 but on 9 and later it changes the hotspot IP everytime its turned on. its not and orangePi issue which i was assuming – Owais Nizam Feb 26 '20 at 11:04
  • You are right. The same here. Different on 9 by just switching hotspot on/off. And later i cannot test. – blackapps Feb 26 '20 at 11:11
  • sure let me know if you find any help. i have tried this [link](https://www.reddit.com/r/GooglePixel/comments/8vypfb/hotspot_ip_no_longer_192168431_on_dp4/) as well but no luck – Owais Nizam Feb 27 '20 at 05:16

0 Answers0