Question

I am working on an application that consists of an Android mobile phone sending information to a PC. I use Wifi to do this, the Android and the PC are connected to the same AP. It works perfectly, the only problem is that I have to keep updating the IP of the PC when creating the socket in Android.

Android(Client):

Socket socket = new Socket("here I write my PC ip",8603);

PC(Server):

ServerSocket welcomeSocket = new ServerSocket(8603);

Is there a way to get the IP of my PC using some code in Android?. Or some way to get all the IPs that the router can send information to?.

Thanks in advance.

Was it helpful?

Solution

you need a service discovery mechanism. Broadcast UDP package in the sub network is the most simple way.

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