简体   繁体   English

android远程服务器

[英]android remote server

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. 我正在构建一个Android应用程序,我希望该应用程序的所有用户共享信息,并在服务器中放置一个php脚本。
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. 我的每个应用程序用户每隔几秒钟就会向其当前位置发送php脚本(服务器)。
i want the php script to send back to each user, the locations of all his friends. 我想将php脚本发送回每个用户,他所有朋友的位置。 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 ? 1.我是否应该仅将请求发送到服务器,并且在同一请求中得到包含我所有朋友职位的答复?
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? 2.我是否应该进行2种方式的通信(也许使用套接字?),并且每当服务器获得更新时,他都会将其发送给所有用户? (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 ? 3.如果我使用的是数字2,我是否应该有某种事件监听器,将等待并查看服务器是否收到新消息?

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. 每个朋友在更新位置时都会将数据发送到服务器,该数据可以存储在mysql数据库中。 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). 也许当一个人更新位置时,可以将推送通知发送给他的每个朋友(使用c2dm进行推送通知既简单又有效)。 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. 回答您的问题:1.当您发送位置信息时,应该通知您的朋友。 so you updating and retrieving mysql data wont serve the purpose. 因此,更新和检索mysql数据将无法达到目的。 your friends should know, that its time for them to retrieve values from mysql. 您的朋友应该知道,现在是时候从mysql检索值了。 hence the push notification to your friends. 因此向您的朋友推送通知。

  1. for a million users, if you wish to use push notifications, you might need to purchase the appropriate plans. 对于一百万个用户,如果您希望使用推送通知,则可能需要购买适当的计划。 some data can be sent along with push notifications, and if that data size is enough for you, you might not need your client to make connection with the server at all to retrieve data. 某些数据可以与推送通知一起发送,并且如果该数据大小足以满足您的需求,则可能根本不需要客户端与服务器建立连接即可检索数据。 which thus removes load from your server. 这样可以减轻服务器的负载。 and if data size is too big, then your client will have to contact the server. 如果数据太大,那么您的客户端将不得不与服务器联系。 in that case your server should be able to respond to a maximum of 1,000,000 users(a rarity) http requests. 在这种情况下,您的服务器应该最多可以响应1,000,000个用户(很少)的http请求。 which i'm not sure if your server can handle 我不确定您的服务器是否可以处理

i hope the answer helped. 我希望答案会有所帮助。 do ask if you have any further queries. 请问您是否还有其他疑问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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