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