如何建立与Google Firebase XMPP服务器的连接?

时间:2018-10-12 10:31:41

标签: c++ firebase firebase-cloud-messaging xmpp swifter

我正在尝试使用Swifter在C ++中建立与FCM XMPP服务器的连接。但是在第一个请求之后,服务器向我发送了未知数据,并且库通过XMLError使我断开了连接。 就像

客户:<?xml version="1.0"?><stream:stream xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" to="gcm.googleapis.com" version="1.0"> 服务器:\ x15 \ x03 \ x01 \ x00 \ x02 \ x02 \ x46 我正在使用的设置:

SimpleEventLoop eventLoop;
BoostNetworkFactories networkFactories(&eventLoop);

ClientOptions co;
co.manualPort = 5236;
co.manualHostname = "fcm-xmpp.googleapis.com";
co.useTLS = ClientOptions::UseTLS::RequireTLS;
co.sessionShutdownTimeoutInMilliseconds = 2000;

Client client("<myid>@gcm.googleapis.com", "mypass", &networkFactories);

client.setAlwaysTrustCertificates();

client.onDataRead.connect([&] (const SafeByteArray &smt) {
    std::cout << "onDataRead" << std::endl;
    for (auto &c : smt) {
        std::cout << std::hex << (int)c << " ";
    }
    std::cout << std::endl;
    std::cout << std::string(smt.begin(), smt.end()) << std::endl;
});

client.onDataWritten.connect([&] (const SafeByteArray &smt) {
    std::cout << "onDataWritten" << std::endl;
    std::cout << std::string(smt.begin(), smt.end()) << std::endl;
});

client.onDisconnected.connect([&] (const boost::optional<ClientError> &smt) {
    std::cout << "onDisconnected" << std::endl;
    std::cout << smt.value() << std::endl;
    client.connect(co);
});

client.connect(co);
eventLoop.run();

0 个答案:

没有答案