Android 客户端-服务器架构:GCM 与 Web 服务 [英] Android Client-Server architecture: GCM versus webservice

查看:32
本文介绍了Android 客户端-服务器架构:GCM 与 Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有本地数据库的 Android 应用程序,其中包含有关存储在设备上的图片的信息.我想创建一个带有图片的服务器,这些图片可以按需提供给安装了我的应用程序的所有设备.所以我的应用程序可以提供本地图片或来自我服务器的图片,还需要一些与这些图片相关的信息.

I have an Android application with a local database that contains information about pictures stored on the device. I want to create a server with pictures that could be provided on demand to all devices that have my application installed. So my application can provide local pictures or pictures from my server and also needs some information related to those pictures.

我分析了 GCM,它非常适合消息通信,但由于消息的大小限制为 4kb,我无法发送图片.我的想法是有这样的东西:

I analyzed GCM and it great for message communication, but since the size of the message is limited to 4kb I can't send the pictures. My idea was to have something like this:

我的问题是:在这种情况下,GCM 通信是否有用,还是仅通过 Web 服务进行客户端-服务器通信会更有效?

我假设如果我使用 GCM,在服务器-客户端通信中我只使用下面的代码 "Bitmap Fun"示例接收图片

I assume that if I use GCM, in the server-client communication I only use the code bellow as in "Bitmap Fun" example to receive the picture

 BitmapFactory.decodeFile(pictureURL, options);

上述方法需要更多的电池和带宽,因为我一次要求 1 张图片而不是 50 张图片的数组?如果我不使用 GCM,我应该处理什么(例如设备处于待机状态)?

The approach above requires more battery and bandwidth since I am asking for 1 picture at a time instead of an array of 50pictures? If I don't use the GCM, what should I handle (e.g. device is in stand by)?

推荐答案

GCM 仅在服务器需要提醒客户端应用程序有关某些新数据(在您的情况下为新图片)时才有用.即使客户端应用程序未运行(或在后台运行),它也允许服务器向客户端发送数据.在这种情况下,绿线是有意义的 - 服务器可以通过 GCM 向客户端发送图片信息.然后,正如你用红线指定的那样,客户端会向服务器询问图片本身.

GCM is only useful if the server needs to alert the client application about some new data (in your case new pictures). It allows the server to send data to the client even while the client app is not running (or running in the background). In that case the green line makes sense - the server can send picture info to the client via GCM. Then, as you specified with the red line, the client would ask the server for the picture itself.

你用询问图片标记的蓝线应该直接从客户端到服务器.客户端无法向 GCM 服务器发送请求(注册/注销 GCM 服务的请求除外).

The blue line that you marked with ask for pictures should go directly from the client to the server. The client can't send requests to the GCM server (except of requests to register/unregister to/from the GCM service).

如果从服务器向客户端发送图片总是由客户端发起,则不需要GCM.

If the sending of pictures from the server to the client is always initiated by the client, you don't need GCM.

此外,您可以查看这个问题详细了解如何通过 GCM 发送图片.

In addition, you can check this question to learn more about sending images via GCM.

这篇关于Android 客户端-服务器架构:GCM 与 Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆