douwen3083 2014-08-04 16:11
浏览 109

如何将数据从数据库推送到客户端,如信使服务?

I am trying to code a messenger service that will store sent messages in a server and then push the message to all devices connected to the server.

The messenger will be used in a classroom environment and the messages will never be sent to one individual device. At the moment a message can be sent and stored in the database but the app needs to be refreshed for all the messages to be displayed. A simple way would be to continuously run the stored procedure but that would require extra bandwidth and i'm sure there is a better way to do it.

I am currently coding in Android Studio and I'm using MySQL as my database and PHP for my stored procedures. I am very new at Java and this type of coding so any help will be appreciated.

Thanks

  • 写回答

2条回答 默认 最新

  • dsgrgaz321973284 2014-08-04 16:18
    关注

    Yes, what you are suggesting is named "polling" => check if the server has some updates each 10sec or something like that. You're right, it's evil (drains the battery, use a lot of bad=ndwidth, etc.)

    What you need is a "push" service. If you are working with Android, the easiest way of doing it is to use GCM (Google Cloud Messaging) : http://developer.android.com/google/gcm/index.html

    This little guy will provide you a way of notifying all the devices that theure have been some changes on the server.

    It's pretty well done (if it can't reach the devices, it will try again with an exponential time delay, etc.).

    评论

报告相同问题?

悬赏问题

  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形