简体   繁体   中英

Connecting two Android phones to transfer data between them over WIFI

Actually i am developing tracking app and want to send Location updates between two Android phones so that both can track one another over the Map. My application must get real time updates from other android device for better tracking.
I Have searched couple of techniques but don't know which one is best

Using Sockets: making one device as Server while other as Client
Possible Limitation:

  • What if IP address of Server is changed (because WIFI don't have a static IP)
  • Cannot access if the IP address of server is private
  • Only client can connect to Server and Server cannot connect to Client

Using Intermediate Server: create an intermediate server and make a communication via that server.
Possible Limitation:

  • Slow because each Android device first send these updates to server and then server push these updates to other android device

Please provide me your suggestion about which one is the best way to do this.

Since you didn't state the Device API level you want to support I'll provide you with an option for Android v4 (API level 14) devices. It's called Wi-Fi Direct and allows p2p connections between phones. It's essentially your socket approach, but allows easy neighbour discovery and allows transfers in both directions.

Well wifi is out.. Not for your stated purpose at least. Unless your map is quite small. Wifi is for say 100 meters (on a really good day)

Not knowing as much about android as I do of other mobiles, I'd say you're in for some pain. I'd suspect connecting to your phone with a peer to peer might be a real slog.. some providers won't let it happen.

I have an approach more than an answer..
From an android phone, see if you can get your ip address.
From a desk, ping that ip address.
If it works, you're well on your way..
Id even say given the size of your info, you could use pinging as your main data carrier.
Pings can contain more than just random bytes. You could include an ID, and GPS in the contents you send in your ping.
--- perhaps include a check sum ---

Do most of the work desk to phone, because development would be faster.. Then when your phone is capable of catching the pings.. Well then sending the ping should be easy as.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM