如何使用C++-XMPP握手将XMPP消息节格式化为GCM
How to format XMPP message stanza to GCM using C++ - xmpp handshake
握手完成,并从GCM-xmpp连接接收到<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
。现在,我正在格式化并发送从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套接字正在关闭,并且没有收到ack。知道吗,我在这里做错了什么?
我试图发送的实际消息如下
Sending msg=<message id="150827111504042682"><gcm xmlns="google:mobile:data"> { "to":"eA_hcHITvwo:APA91bEB83Gci", "message_id":"150827111504042682", "time_to_live":10 } </gcm></message>
在收到GCM的成功消息后,在发送任何节之前,我需要发送任何ack吗?或者我需要在大括号和名称值对之后添加换行符吗?
信息流
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(中有冒号?我需要把它转换成某种东西吗?这样谷歌xmpp处理器就不会和json冒号("to":"deviceToken"(混淆了?
末尾缺少一个逗号
sync << "'to':'eA_hcHITvwo:APA91bEB83Gci'";
,
它应该是这样才有效:
sync << "'to':'eA_hcHITvwo:APA91bEB83Gci',";
也许这能解决你的问题。
最后我从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/
谢谢李的提问。不幸的是,目前还不清楚是谁回答的,但非常感谢最终回答的人。不确定为什么协议没有记录在正确的地方。
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( [userName] [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
- boost::进程间消息队列引发错误
- 在线编译器中的分段C++没有打印消息
- C++错误消息*成员参考.**初学者*
- C++格式化输出问题
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- 如何通过参数抛出错误消息
- 从服务器传输到客户端的消息不会出现
- 格式化浮点值:返回默认值
- ROS2 动态消息模板
- C++秘密消息学校作业
- glad 导致 glfwSwapBuffers 返回错误消息
- 从函数(不抛出函数)返回异常以进行消息格式化?
- 字符* 文本消息[] 如何在内存中格式化?
- 格式化输出以显示在错误列表的消息部分中
- 如何使用可选的格式化消息实现符合标准的断言宏?
- 网络消息格式化很多字符,int,在CC++中转换
- 如何在不将字符串对象嵌入自定义异常类的情况下重新格式化错误消息
- 使用boost program_options处理帮助消息,删除默认值或重新格式化帮助消息
- 使用占位符格式化消息