Q:

How to programmatically connect to a particular PC of unknown IP from a WiFi network?

I want to connect and transfer data between a PC and an Android device both of which are on the same local WiFi network.
I cannot use the local IP as such in the code to actually get the connection going because it does not remain constant every time. I know I can set the local IP to be constant but I am looking for a more general solution to the problem.
Having a central server is also not what I'm looking for, because I want to transfer data offline.
I am not an expert on networks as you might have already guessed, so if I am missing something out, let me know. Also is there some API in android that could do this?

A:

You should look at broadcasting. This is technique of sending your packets to all devices (IP's) in a subnet. It would look something like that:

Android 192.168.0.101: Send message packet to broadcast address
192.168.0.254
PC 192.168.0.110: Reply to 192.168.0.101's broadcast message
Android now knows PC's IP address and can communicate directly

It's really simple. You can find JAVA sample in this SO question: https://stackoverflow.com/questions/12999425/simple-udp-broadcast-client-and-server-on-different-machines

