Question

I am working on client server threads via using socket programming... Both client and server are android devices, Server with Hotspot enabled and client with wifi enabled. Now client has password of Server and it already get connected to server but now I need IP of server or host address for sending and receiving data between them. Server has its IP and client has its IP but how Client can automatically get Server IP?

I used

WifiInfo wif = mWifiManager.getConnectionInfo();
int wifI = wif.getIpAddress();

String wifiS = ( wifI & 0xFF)+ "."+((wifI >> 8 ) & 0xFF)+"."+((wifI >> 16 ) & 0xFF)+"."+((wifI >> 24 ) & 0xFF);

But find out that it gives only client's own IP... What's the solution for this?

Was it helpful?

Solution

Have a look at WifiManager.getDhcpInfo() when connected to the hotspot. The Hotspot likely acts as a DHCP server. DhcpInfo.gateway or DhcpInfo.serverAddress should give you the hotspot's IP. –

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top