Just before connecting to a ws(s) endpoint, a short http-ping request is made to ensure server's accessibility.
The code looks like:
Code: Select all
function connect() {
var self = this;
http.request( { url:self.pingUrl, async:true,
success:function( resp ){ self.connectWS(); },
error:function( resp ){ console.log( 'Ping ' + self.pingUrl + ' not accessible: ' + JSON.stringify( resp ) ); }
} );
}
function connectWS() {
var self = this;
var ws = new sockets.websocket( 'wss://myserv.com' );
self.ws = ws;
ws.onclose = function ( e ) {
console.log( 'WebSocket closed. Will try to re-open it...' );
self.timer = setInterval( function () {
if( !self.ws || self.ws.readyState == self.ws.CLOSED ) self.connect();
}, 120000 );
};
}
[2017-02-16 11:27:20.088] [core] WebSocket closed. Will try to re-open it...
[2017-02-16 11:29:20.227] [core] Ping https://ping.myserv.com not access
ible: {"status":-1,"statusText":"Out of memory"}
If I restart the server, it runs smoothly again.
What can I do to ease the memory pain?