Should I use GCM for real time communication between devices?

假装没事ソ 提交于 2020-01-01 09:42:36

问题


I am making a chat application for android. For that, I decided to use GCM (Google Cloud Messaging). But having researched a bit about it,I have read that it shouldnt be used for something like chat.

I will be implementing Upstream messaging (sending data from the device to the GCM directly, without a send-to-sync). Here are my concerns:

  • Will the messages transfer instantly? (will be fast enough that the user can see 'typing'/seen)
  • If all devices are online, what is the guarantee of the message from GCM reaching the client.

The main reasons I want to use GCM is

  1. GCM uses the least amount of battery life
  2. This is an android-only app.

If GCM is not what I should use, what should I use?


回答1:


I am working on a similar requirement and Looking at the requirement of being able to show feedback such as typing/lastseen etc, as per my knowledge XMPP based solution would be appropriate.

you can try with available xmpp server like ejabberd/mangooseim (open source) by installing it on your server and use asmack or any other client side java library to communicate it with your server. (There are lot of tutorials available for this).

With this much setup you will be able to get to the stage where you are able to get status such as "typing", "gone" which whatsapp and also some chat clients like gtalk/pidgin shows.

It would roughly give an idea of how existing chat clients work.

Ejabberd is completely written in erlang and if you want to extend any functionality erlang knowledge is must. (it is specifically designed for highly concurrent fault tolerant and non-stop systems, which was helpful in chat applications.

GCM would be definitely able to communicate between the android phones 99.99%of times with not much delay but if you want to have roasters status like normal chat applications, you will have to reinvent the wheel completely.

Update:

Here are the considerations.

from client A to client B I want to send chat messages with roasters and dont require to store messages on any central server but just on the clients - XMPP (like whatsapp)

in case you require all the communication to be stored in server - XMPP with sql driver or mongodb driver / gcm (Depending on your time and resources)

in case you require communication between devices not necessarily chat, then gcm should be sufficient. I am using this approach in my app currently which is live on playstore with beta version and it absolutely works fine in most of the cases. I havent seen much of bottle necks as of now.



来源:https://stackoverflow.com/questions/30151587/should-i-use-gcm-for-real-time-communication-between-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!