I have two android devices and they are connected to a same WiFi network. One device acts as the server and the other acts as the client. I don't know the ip of the server but I know the port number. How can I find the server and connect to it?
Asked
Active
Viewed 1,805 times
0
-
I hope this post can help : http://stackoverflow.com/questions/3345857/how-to-get-a-list-of-ip-connected-in-same-network-subnet-using-java – Radi Dec 26 '16 at 12:22
-
I didn't find a chance to try this solution but seems a good way. – Mans Dec 27 '16 at 16:29
1 Answers
3
One option is to use UDP broadcasting. Your server is waiting for requests on a specific port and network interface. Then your client send a dummy request against the broadcast address (like for instance 192.168.1.255) and once the server replies you can get the server's ip address.
Once you're done, the client can shutdown the udp socket connection and start tcp communication as you need.
A good start might be this: http://michieldemey.be/blog/network-discovery-using-udp-broadcast/
Hope this helps

Lino
- 5,084
- 3
- 21
- 39