【问题标题】:How to format XMPP message stanza to GCM using C++ - xmpp handshake如何使用 C++ 将 XMPP 消息节格式化为 GCM - xmpp 握手
【发布时间】:2015-11-20 20:24:46
【问题描述】:

握手完成并从 GCM xmpp 连接收到<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>。 现在,我正在格式化并将 send-to-sync 消息从 APP 服务器发送到 GCM 以发送到移动设备,如下所示

ostringstream sync;
sync << "<message id=\"1234\">";
sync << "<gcm xmlns=\"google:mobile:data\">";
sync << " { ";
sync << "\"to\":\"eA_hcHITvwo:APA91bEB83Gci\",";
sync << " \"message_id\":\"1234\",";
sync << " \"time_to_live\":" << 10;
sync << " } ";
sync << "</gcm></message>";
string msg = sync.str();
sslSock_->write(msg.c_str(), msg.length());
std::string syncResp = readFromGcm(); // ack/nack

不幸的是,SSL 套接字正在关闭并且没有收到确认。任何想法,我在这里做错了什么?

我尝试发送的实际消息如下所示

Sending msg=&lt;message id="150827111504042682"&gt;&lt;gcm xmlns="google:mobile:data"&gt; { "to":"eA_hcHITvwo:APA91bEB83Gci", "message_id":"150827111504042682", "time_to_live":10 } &lt;/gcm&gt;&lt;/message&gt;

在收到来自 GCM 的成功消息后和发送任何节之前,我是否需要发送任何确认? 或者我需要在花括号和名称值对之后添加换行符吗?

消息流 Sent1: <stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'> Received1: <stream:stream from="gcm.googleapis.com" id="EBA37684C852364D" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"> Received2: <stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features> Sent2: <auth mechanism='PLAIN' xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>ADM2NTU4MjFZVV0F1LVJV</auth> Received3: <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/> Sent3: <message id=""><gcm xmlns="google:mobile:data">{"to":"eA_hcHITvwo:APA91bEB83Gci","message_id":"150827161659237590","data":{"title":"Alert: mydata","text":"mydata refresh"},"time_to_live":10,"delay_while_idle":true,"delivery_receipt_requested":true}</gcm></message> Received4: None. Socket closed

我刚刚注意到设备令牌 (eA_hcHITvwo:APA91bEB83Gci) 中有冒号?我是否需要将其转换为某种东西,以便 google xmpp 处理器不会与 json 冒号(“to”:“deviceToken”)混淆?

【问题讨论】:

    标签: android c++ unix xmpp google-cloud-messaging


    【解决方案1】:

    您在结尾处缺少逗号:

    sync &lt;&lt; "'to':'eA_hcHITvwo:APA91bEB83Gci'";,

    应该是这样才有效:

    sync &lt;&lt; "'to':'eA_hcHITvwo:APA91bEB83Gci',";

    也许这会解决你的问题。

    【讨论】:

    • 在收到来自 GCM 的成功消息后是否需要发送任何 ack?
    • 对于您的应用服务器从 CCS 收到的每条消息,它都需要发送一个 ACK​​ 消息。它永远不需要发送 NACK 消息。如果您不发送消息的 ACK,CCS 只会重新发送它。您是否收到任何 NACK 错误消息作为回报?您可以尝试通过转义它们(“\””)将 JSON 单引号更改为双引号,因为 JSON 不验证单引号字符串,尽管我不知道谷歌如何处理 XMPP JSON。
    • 我尝试使用双引号,但没有运气。还尝试在身份验证成功消息后发送 ack,但仍然没有运气。
    • 我刚刚注意到设备令牌中有冒号?我是否需要将其转换为某种东西,以便 google xmpp 处理器不会与 json 冒号混淆?
    【解决方案2】:

    终于得到了https://developers.google.com/cloud-print/docs/rawxmpp的答复 和 http://grokbase.com/p/gg/android-gcm/13a2zrnn34/gcm-ccs-xmpp-3rd-party-server-implementation

    xmpp 握手的另一个例子 https://tech.yandex.com/disk/doc/dg/concepts/xmpp_xmpp-connection-docpage/

    感谢提出问题的 Lee Chua。虽然非常感谢最后回答的人,但不幸的是,目前尚不清楚谁回答了。 不知道为什么协议没有记录在正确的地方。

    C (authenticate): <stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'> <auth mechanism='PLAIN' xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>base64Enc(\0[userName]\0[password])</auth> S: <stream:stream from="gcm.googleapis.com" id="352584B87B657F7F" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"> <stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features> <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/> C (pre Binding): <stream:stream to='gcm.googleapis.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'> S: <stream:stream from="gcm.googleapis.com" id="7C0C770AED97331C" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"> <stream:features><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features> C: (bind): <iq type='set' id='bind-1' to='gcm.googleapis.com'> <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'> <resource>core</resource> </bind> </iq> S: <iq from="gcm.googleapis.com" id="bind-1" type="result"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>[senderID]@gcm.googleapis.com/coreAB8CB2E7</jid></bind></iq> C: (session request): <iq to='gcm.googleapis.com' type='set' id='sess_1'> <session xmlns='urn:ietf:params:xml:ns:xmpp-session'/> </iq> S: single byte message and then S: <iq from="gcm.googleapis.com" type="result" id="sess_1"/> C: first stanza sent successfully

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-11
      • 2014-12-26
      • 2020-11-24
      • 1970-01-01
      • 2016-03-21
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多