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?


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 Send message packet to broadcast address
  • PC Reply to'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

  • +1 but is this the most efficient way to go about this? – shyam Dec 5 '14 at 9:18
  • 2
    it is the ONLY way to go about it. – Mawg Dec 5 '14 at 15:33
  • @Mawg I'm gonna take your word for it then. – shyam Dec 6 '14 at 4:40
  • Think about it. If you want to sent a letter (how quaint) to that nice grrrl who smiled at you in the pub lat night, your going to have to walk around town pushing a note throw every letter box asking her to get in touch – Mawg Dec 6 '14 at 9:24
  • Well, its more similar to asking a postman of giving letters to all the girls in town. One more alternative is phonebook, or in your case - some kind of external site/api (tracker in bitorrent terms). – Dissimilis Dec 6 '14 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.