I have two backends communicating to each other via sockets. On the sending one i only blast out. On the receiving one
const socketIOClient = require('socket.io-client');
const sailsIOClient = require('sails.io.js');
const io = sailsIOClient(socketIOClient);
io.sails.url = "http://route.to.my.backend";
io.sails.initialConnectionHeaders = {secret: process.env.SOCKETSECRET};
when the socket connection breaks, the sockets won't reconnect. I tried it with:
io.sails.forceNew = true;
but it doesn't work. How can i force them to reconnect?
This is an old question, but since I have a solution that seems to be undocumented (and no other answers were provided), I am posting for future reference.
Problem: my
SailsSocketinstance does not attempt reconnection while using thesails.io.jsnode moduleSolution: manually set
io.socket._raw.io._reconnectiontotrueSpecifically, when your socket disconnects, set the above property to
trueand the socket will automatically attempt reconnection.It is rather ugly, because you must access the underlying
socket.iosocket client with._raw, get the socket's manager with.io, and set another [pseudo-] private variable,._reconnection, totrue.It should be emphasized that this whole "not reconncting" issue is only present using
sails.io.jsin node, while the browser implementation works fine.Tested on:
sails 0.11.0,sails.io.js node SDK 1.1.12,node 6.11.2