I am trying to establish a (all time) connection between my computer and my android phone. So far I have been able to do so, but I have to manually enter the ipv4 address of the server when connecting to a clien e.g socket = new Socket("server ipv4 here", 999);
. However, when the network configuration changes, so does the ip address and I have to go to cmd and find the new server's ip using the ipconfig command. For example, suppose that my computer(server) is connected via ethernet and my phone(client) via WiFi and I have used the ethernet ip to connect my client to the server. Then if I connect my server via WiFi, the ip will change so a client-server connection can't be establish. This can also occur if I move both my computer and phone under a different network.
So my question is, is there a way to get a server ip from a client under the same network?
This is what I have tried to do but fail
InetAddress address = InetAddress.getByName("Computer/server host name");
socket = new Socket(address, 999);`
where "computer/server host name" is the host name gotten when calling InetAddress.getLocalHost().getHostName();
on the server computer.
Thanks!