可以GCM用于Android设备之间发送和接收消息? [英] Can gcm be used to send and receive messages between android devices?

查看:280
本文介绍了可以GCM用于Android设备之间发送和接收消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行GCM客户端应用程序两款Android设备。我得到两个设备的注册标识。我也有一个服务器API密钥。现在的问题是,使用使用卷曲或Zend Framework的一个简单的PHP code,我能够从Web服务器发送消息给我的机器人(当然,我可以播放过)之一。但是,这个在手,有没有办法从一个设备发送一个字符串到另一个?

I have two android devices that runs a gcm client app. I get the Reg IDs of both the devices. I also have a server API key. Now the thing is, Using a simple php code using cUrl or Zend framework, I'm able to send message from a web server to one of my droids (Of course I can broadcast too). But, with this in hand, is there any way to send a string from one device to another?

推荐答案

我的书中引用自己:

您也许会使用GCM为对等网络通讯,无一台服务器
  你自己。实际上,每个Android应用程序是它自己的服务器,使用你同样的JAR
  可能会在网络应用使用您的Andr​​oid应用程序内发送消息给其他一些
  派对。例如,你可以实现一个聊天系统中无需专用
  聊天服务器。

You might be tempted to use GCM for peer-to-peer messaging, without a server of your own. In effect, each Android app is its own server, using the same JAR you might use in a Web app inside your Android app to send messages to some other party. For example, you could implement a chat system without having a dedicated chat server.

这里的危险在于,这需要你的API密钥被嵌入
  你的Andr​​oid应用程序。任何与该API密钥是完全有能力的锻造
  从你的邮件。你可以放置在该API密钥的IP地址限制
  不太可能有帮助,因为您的合法用​​途可能来自任何IP地址,而不是
  只是一些单个服务器。由于APK文件中找到字符串的魔法并不是那么困难
  对于有伴的倾向,把你的API密钥您的APK文件是一个危险的
  移动。

The danger here is that this would require your API key to be embedded within your Android application. Anyone with that API key is perfectly capable of forging messages from you. The IP address restrictions you could place on that API key are unlikely to help, since your legitimate uses might come from any IP address, not just some single server. Since finding magic strings in APK files is not that difficult for those with the inclination, putting your API key in your APK file is a dangerous move.

因此​​,你会想一些自己的服务器作为中间人。

Hence, you will want some server of your own as a middleman.

这篇关于可以GCM用于Android设备之间发送和接收消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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