I have a weird problem with Autobahn|JS and the push API on Poloniex.com. I connect to their API to fetch all messages in their chat and after 1-2 hours, the websocket close without errors, nothing to help me to debug.
I have tested the behavior in 3 langages (PHP, NodeJS and JS) and 2 have problems (PHP and NodeJS), my JavaScript test run since 1 day without problems.
The code is very simple:
var connection = new autobahn.Connection({url: 'wss://api.poloniex.com', realm: 'realm1'});
connection.onopen = function (session) {
function onevent(args) {
console.log("Message:", args[3]);
}
session.subscribe('trollbox', onevent);
};
connection.open();
I have tested with Supervisor for NodeJS and same problem, after 1-2 hours, no response, no error, just not receive message anymore.
I'm new to websocket so I imagine I can test more but the fact that all works in Javascript confused me.
Didn't find a solution so I have implemented my proper "ping". I unsubscribe and subscribe every X minutes (my test run since 1 day with 5 minutes interval). No more deconnection and no missed message from the trollbox.
AUTOBAHN_DEBUG = true;
var autobahn = require('autobahn');
(function trollbox() {
console.log("\n------------- OPEN CONNECTION ---------------\n");
var connection = new autobahn.Connection({
url: 'wss://api.poloniex.com',
realm: 'realm1',
max_retries: -1
});
connection.onopen = function (session) {
function onevent (args) {
// Do somethings...
console.log(args[3]);
}
session.subscribe('trollbox', onevent);
setTimeout(function () {
console.log("\n------------- CLOSING CONNECTION ---------------\n");
connection.close();
}, 300000);
};
connection.open();
setTimeout(trollbox, 300200);
})();