doumi1912 2012-12-29 19:27
浏览 99

什么是使用apache,php和mysql实现实时推送消息的最佳方式?

i'm trying to implement a chat application for android (where users can communicate people who are in same location). i'm thinking it of an facebook messenger with Geo specific oriented. i came across to terms like repeated pull, comet, bosh, websockects, socket programming, xmpp(which requires xmpp capable server like openfire) etc to do this. But my resources are fixed like apache, php (codeignter) and MySql only. I need to find the efficient to way to do this. Guys i need this. Please help me.

Thank you, abbiya

  • 写回答

1条回答 默认 最新

  • duan0424 2012-12-29 19:36
    关注

    The preferred approach on Android is Google Cloud Messaging.

    Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device. This could be a lightweight message telling your app there is new data to be fetched from the server (for instance, a movie uploaded by a friend), or it could be a message containing up to 4kb of payload data (so apps like instant messaging can consume the message directly).

    The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device. GCM is completely free no matter how big your messaging needs are, and there are no quotas.

    Essentially, it works like this: Your server talks to Google, and Google pushes the message in real-time (or nearly so, as long as the device is powered on and connected to the Internet) to the Android device(s). There's a registration process that happens on the Android device the first time the app is installed (and at future points to revalidate the registration). In your Android app, it's your responsibility to send this registration ID to your server so you can store it for future use. Your server uses this registration ID when it wants to push a message to that device.

    The communication protocol between your server and Google is JSON over HTTPS. Your server can use any languages/technologies, as long as it can communicate with Google's servers. A PHP/MySQL application can definitely meet the basic requirements for the service:

    Before you can write client Android applications that use the GCM feature, you must have an application server that meets the following criteria:

    • Able to communicate with your client.
    • Able to fire off HTTPS requests to the GCM server.
    • Able to handle requests and resend then as needed, using exponential back-off.
    • Able to store the API key and client registration IDs.

    On the client side, the Android device must be running API version 8 (Android 2.2) or later. Of course, it's also your Android app's responsibility to process incoming messages (using a BroadcastReceiver, as the Android system sends an Intent to your receiver whenever a message arrives), which allows you to handle messages however you want.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题