上传消息到服务器应用程序 [英] Upstream message to server app

查看:135
本文介绍了上传消息到服务器应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地从PHP服务器页面向JAXL的Android客户端发送数据。



我仔细阅读了Google Cloud Message Offical网站的指南..对于上游只有这些文件:

pre $ public void onClick(final View view){
if(view == findViewById( R.id.send)){
new AsyncTask(){
@Override
protected String doInBackground(Void ... params){
String msg =;
尝试{
Bundle data = new Bundle();
data.putString(my_message,Hello World);
data.putString(my_action,SAY_HELLO);
String id = Integer.toString(msgId.incrementAndGet());
gcm.send(SENDER_ID +@ gcm.googleapis.com,id,data);
msg =发送信息;
} catch(IOException ex){
msg =Error:+ ex.getMessage();
}
return msg;
}

@Override
protected void onPostExecute(String msg){
mDisplay.append(msg +\\\
);
}
} .execute(null,null,null);
} else if(view == findViewById(R.id.clear)){
mDisplay.setText();




$ b




接收应用服务器上的XMPP消息

 当GCM收到上游来自客户端应用程序的消息传递调用,它将生成用于发送上游消息的必要XMPP节。 

GCM添加​​类别和字段,然后发送一个节点,如
以下内容应用服务器:



 < message id => 
< gcm xmlns =google:mobile:data>
{
category:com.example.yourapp,//知道哪个应用发送了它
data:
{
hello: world,
},
message_id:m-123,
from:REGID
}
< / gcm>
< / message>

但是现在我有一些问题,因为上游文件有限。



1-)Android发送JSON数据,发送者ID为上游...但是当我注册到api时,还没有被问及应用服务器。发件人身份识别我的gmail帐户的应用程序包。不是应用服务器。所以gcm发送客户端发来的数据?如何GCM知道我的应用程序服务器。

2-)我的预算有限,我的服务器是共享帐户Web服务器。所以我必须使用PHP ...但我已阅读文档,您的应用程序服务器应该是持久连接,而不是连接&定期断开...我可以使用应用程序服务器作为PHP?该GCM连接腓scrpit其中evulate数据和Android客户端发回响应?


解决方案

  1. 您可能知道,您的服务器和GCM之间的连接需要发件人ID和API密钥。另外,当客户端应用程序想要发送上游消息时,它使用相同的发件人ID。所以GCM知道应该向谁发送上游数据。 您的编程语言没有限制,当然您可以使用PHP。您只需保持与GCM服务器的持续连接。


不关心一些断开连接,请注意,如果您的服务器出现故障,Google会重新发送上游消息,并没有发回一个确认消息给GCM的ACK。

I have successfuly send data from php server page to android client with JAXL..

I have read carefully the guide of Google Cloud Message Offical website.. For Upstream there is only these documents:

public void onClick(final View view) {
    if (view == findViewById(R.id.send)) {
        new AsyncTask() {
            @Override
            protected String doInBackground(Void... params) {
                String msg = "";
                try {
                    Bundle data = new Bundle();
                    data.putString("my_message", "Hello World");
                    data.putString("my_action","SAY_HELLO");
                    String id = Integer.toString(msgId.incrementAndGet());
                    gcm.send(SENDER_ID + "@gcm.googleapis.com", id, data);
                    msg = "Sent message";
                } catch (IOException ex) {
                    msg = "Error :" + ex.getMessage();
                }
                return msg;
            }

            @Override
            protected void onPostExecute(String msg) {
                mDisplay.append(msg + "\n");
            }
        }.execute(null, null, null);
    } else if (view == findViewById(R.id.clear)) {
        mDisplay.setText("");
    }
}

Say this:

Receive XMPP messages on the app server

When GCM receives an upstream messaging call from a client app, it generates the necessary XMPP stanza for sending the upstream message.

GCM adds the category and from fields, and then sends a stanza like the following to the app server:

<message id="">
  <gcm xmlns="google:mobile:data">
  {
      "category":"com.example.yourapp", // to know which app sent it
      "data":
      {
          "hello":"world",
      },
      "message_id":"m-123",
      "from":"REGID"
  }
  </gcm>
</message>

But now I have some questions,because of limited documents for upstream.

1-)Android send JSON data, with sender id for upstream... But when I register to api,have not been asked about app server. Sender Id identfy my gmail account's application with package. Not app server. so where gcm send data that come by client? How to GCM knows my app server..

2-)I have limited budget, my server is shared account web server. So I have to use php... But I have read on document,"Your app server should be persistent connection" not connect& disconnect regularly... Can I use app server as php? that GCM connects Php scrpit which evulate data and respond back to android client?

解决方案

  1. As you may know, the connection between your server and GCM required sender-id and API key. Also when a client app wants to send an upstream message, it uses the same sender-id. So GCM knows to whom it should send the upstream data.

  2. There is no limit on your programming language, of course you can use PHP. You just have to maintain a persistent connection to GCM server.

Don't care about some disconnections, note that Google will retry to send the upstream messages if your server was down, and didn't send an ACK back to GCM for a particular message.

这篇关于上传消息到服务器应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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