[SOLVED]How can i find and communicate with android phones in a local network
-
wrote on 7 Jan 2013, 15:27 last edited by
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.
-
wrote on 7 Jan 2013, 19:19 last edited by
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 255.255.255.0 and local address masked 255.255.0.0 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.
-
wrote on 7 Jan 2013, 19:55 last edited by
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.
-
wrote on 7 Jan 2013, 20:07 last edited by
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).
-
wrote on 7 Jan 2013, 20:17 last edited by
I will try the broadcast option. it's better than asking the user to type in ip addresses
-
wrote on 8 Jan 2013, 06:10 last edited by
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.
-
wrote on 8 Jan 2013, 09:29 last edited by
mdns/bonjour/rondezvous might also be an option for device discovery. If that is available on android that is.
-
wrote on 8 Jan 2013, 09:36 last edited by
Tobias, good point. Your advice pointed to: http://developer.android.com/training/connect-devices-wirelessly/nsd.html
1/8