I have implemented an XMPP client within Node.js (using node-xmpp module) to send and receive notifications from an Android Client:
var xmpp = require('node-xmpp');
var options =
{
type: 'client',
jid: process.env.GCM_PROJECT_ID+'@gcm.googleapis.com',
password: process.env.GCM_PASSWORD,
port: 5235,
host: 'gcm.googleapis.com',
legacySSL: true,
preferred : 'PLAIN'
};
var cl = new xmpp.Client(options);
cl.connection.socket.setKeepAlive(true, 10000);
and this is where the 'online' event gets handled:
cl.on('online', function() {
console.log("online");
});
When Node.js server is started locally everything works fine and i am able to receive upstream messages from Android Clients as well as send downstream messages to Android clients. When my webserver runs on a Heroku dyno though, the 'online' event is never triggered,thus the XMPP Client does not connect and i can't receive upstream nor send downstream messages.
My implementation was based on the following gist: https://gist.github.com/jamesvnz/6756208 where it's author provides sample node.js server code to implement an XMPP server that will integrate with Android's Google Cloud Messaging (GCM) "device to cloud" message functionality - CCS.
So,i can't understand why the XMPP Client doesn't connect when run on Heroku but works perfectly on localhost.