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

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

问题描述

我有一个包含存储在设备上的图片信息,本地数据库的Andr​​oid应用程序。我想创建与可按需提供给安装了我的应用程序的所有设备的图片服务器。所以,我的应用程序可以提供从我的服务器的本地图片或照片,同时还需要有关这些照片的一些信息。

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,在服务器 - 客户端通信我只用code波纹管作为的位图乐的例子来接收图片

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);

上面的方法需要更多的电池和带宽,因为我在同一时间,而不是50pictures数组要求1的画面?
如果我不使用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.

此外,您可以检查<一href=\"http://stackoverflow.com/questions/15436624/gcm-send-image-instead-of-message/15436728#15436728\">this问题以了解更多关于通过GCM发送图像。

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

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

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