Important: Please read the Qt Code of Conduct -

[SOLVED]How can i find and communicate with android phones in a local network

  • I need to search for and find my phone in my local network and then communicate with it. so how should i go about doing it. I think i should be using TCP to transfer the data to the phone, but how do i find the phone in the first place.

  • Technically that would be security hole in smartphone OS if you could find phones in local network (be it home, work or public network). As network owner you could find connected devices but that requires some extra software in your router (e.g. OpenWRT based router could expose connected devices) - still you will have extra problem identifying if device is phone or something different.

    Basically phone must somehow expose itself and be active here. One option is bluetooth - I'm not sure however if you can hook into bluetooth listener. Usually phones keep bluetooth in hidden mode and you will not find them. One correct solution is NFC: that's what NFC was basically created for. You use it to initiate communication between two devices (by touching them) so they can exchange information using Bluetooth (e.g. Nokia and BB10 successfully can exchange photos using NFC or you can use two NFC enabled phones to initiate gaming using two devices in some games, Angry Birds Magic one example).

    Another solution is to have server. Phone could send to server its local IP address. Server will see phone's external address. If external IP address masked using and local address masked matches you can assume that two devices are in the same network. That's not very safe assumption but I guess in 90% cases that would work. After that you can make one phone run server (e.g. using sockets or HTTP library) and other client. While if you have external server I doubt you need another local server.

    That's just some ideas but none of them are Qt specific.

  • sorry but i should have been more clear. both the pc and the phone are in the same local network and both have qt apps on it. now i need these two apps to communicate with each other, but the problem is how do i find out the ip address of the other device.

  • One option is (UDP) broadcast.

    Another option: if you have PC and phone. Make PC server, show PC IP address in app, run server on PC and connect to it from phone. Actually you can even use HTTP what would be much easier in this case (IMHO).

  • I will try the broadcast option. it's better than asking the user to type in ip addresses

  • I personally would recommend looking into multicast as well. IPv6 supports multicast only and there are some good reasons why IPv6 will finally become more popular.

  • Moderators

    mdns/bonjour/rondezvous might also be an option for device discovery. If that is available on android that is.

Log in to reply