i'm building an android application which i want all the user of the application share information throw a php script located in my server.
for example: i have a google Map and i want see all my friend's location. each of my application's users will send his current position the the php script (the server) every numerous of seconds.
i want the php script to send back to each user, the locations of all his friends. what is the best way of doing it ?
i thought of few and will be happy to get help starting them:
1. should i only send requests to the server and in the same request get an answer in return which will include all my friend's position ?
2. should i make it a 2 way communication (using sockets maybe?) and whenever the server gets an update he sends it to all users? (i don't even know how to start doing it..)
3. if i'm using number 2, should i have some kind of event listener which will wait and see if there's a new message from the server ?
the first method would probably be easier to implement.
every friend while updating his location sends data to the server which can be stored in a mysql db. maybe when a person updates a location a push notification can be sent to each of his friends(c2dm for push notification is easy and effective). once the user gets the push notification, it fires a request to the server and gets the necessary data in the same response. this is a simple and reliable method to do it.
the reply was too long for comments so i put it here. answer to your questions: 1. when you send your location, its your friends who are supposed to be notified of that. so you updating and retrieving mysql data wont serve the purpose. your friends should know, that its time for them to retrieve values from mysql. hence the push notification to your friends.
i hope the answer helped. do ask if you have any further queries.
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.