0

I've mounted a small NodeJS web server using Express and node-xmpp-client on an Amazon EC2 instance to use it as a GCM Push Notification Server. I've set everything up but the strange thing is that it only works when I try it local, on my own Macbook, but it won't work on the server: I never receive a "Online" log message from NodeJS, only "connecting...." (check the code below). I've added the server IP to the Google Developers Console and made sure to open the required ports on the EC2 Security Group, but still no change: It works only on local, but nothing on the server. The code looks like this:

var options = {
  type: 'client',
  jid: '<my user id>@gcm.googleapis.com',
  password: GCM_API_KEY,
  port: 5235,
  host: 'gcm.googleapis.com',
  legacySSL: true,
  preferredSaslMechanism : 'PLAIN'
};

xmppClient = new xmpp.Client(options);
xmppClient.connection.socket.setTimeout(0)
xmppClient.connection.socket.setKeepAlive(true, 10000)

xmppClient.on('stanza',
  function(stanza) {
    console.log("Stanza:")
    console.log(stanza.toString());
      if (stanza.is('message') && stanza.attrs.type !== 'error') {
          var messageData = JSON.parse(stanza.getChildText("gcm"));
          if (messageData && messageData.message_type == "ack" && messageData.message_type != "nack") {
             //...
          }
      } else {
          console.log("error");
          console.log(stanza);
      }
});

xmppClient.on('error', function(e) {
    console.log("Error occured:");
    console.error(e);
    console.error(e.children);
});

xmppClient.connection.socket.on('error', function(err) {
  console.log('error : ',err);
});

xmppClient.on('reconnect', function() {
    console.log('reconnecting....');
});

xmppClient.on('connect', function() {
    console.log('connecting....');
});


xmppClient.on('online', function() {
  console.log("Online");
  connected = true;
});

I only get a "connecting...." log message.

Please help me, I'm going crazy

  • Can you provide us the logs? have you tried this tutorial? https://github.com/node-xmpp/node-xmpp-server. Also, found this Stack Overflow ticket, it is related to your problem. you may check the solution answered by the community. http://stackoverflow.com/questions/22566024/cant-connect-to-gcm-using-node-xmpp-client – Android Enthusiast Jan 06 '16 at 07:16
  • The logs only show "connecting...", and after a while the connection closes. I also tried the solution you posted, but nothing. I ended uploading the very same code to Heroku and it works perfectly. I'm sure it has to do do with the security EC2 provides. – Santiago Martí Olbrich Jan 06 '16 at 14:14

0 Answers0