Can't connect to GCM using node-xmpp client

2020-04-17 06:24发布

问题:

I am attempting to run gcm server using node-xmpp, but xmpp client does not seem to open at all and closes after timeout.

var xmpp = require('node-xmpp-client');

var options = {
  type: 'client',
  jid: 'fake-project-123@gcm.googleapis.com',
  password: 'ApiKeyHere',
  port: 5235,
  host: 'gcm.googleapis.com',
  legacySSL: true,
  preferredSaslMechanism : 'PLAIN'
};

console.log("Creating XMPP Application");

var cl = new xmpp.Client(options);

cl.on('online', function()
{
    console.log("XMPP Online");
});

Rest of the code was omitted. In the console, I never get to see "XMPP Online". How do I check if xmpp is even connecting, and where it fails to open?

回答1:

I got the same problem and found out that the Connection.startStream() was never called, although the socket was opened successfully.

Here's my pull request: https://github.com/node-xmpp/node-xmpp-client/pull/61

Until it gets merged, you can use my fork, which should work for GCM: https://github.com/Riplexus/node-xmpp-client



回答2:

I followed this from gcm google groups and it worked for me. And for timeouts you can try xmppClient.connection.socket.setTimeout(0) xmppClient.connection.socket.setKeepAlive(true, 10000) Don't forget to whitelist your server ip in google console.



回答3:

I have given up the hope of using node-xmpp and game smack client a try. Sadly it did not work, but I did get an error saying my project is not whitelisted. When project is whitelisted, it can receive messages from android devices, which is exactly what I need and is the sole reason why I went straight to CCS (XMPP). Without the whitelist, it is not possible to use CCS (XMPP) for sending the messages to android devices. In order to use HTTP method, the project does not need to be whitelisted, but has a limitation to being able to send messages only. I have signed up upstream GCM but have yet to receive response.

https://services.google.com/fb/forms/gcm/