Reputation: 347
I have a simple node.js server set up with an angular.js frontent and I am trying to implement Socket.IO so I can live update data on my page but I am running into an issue with double Socket.IO connections opening and hanging my page.
var self = this;
self.app = express();
self.http = http.Server(self.app);
self.config = config;
self.io = require('socket.io')(self.http);
self.io.on('connect', function() {
console.log('Connected');
});
and in my angular.js factory I have
var socket = io.connect();
If I load up my page on Safari or Chrome on iOS (pretty sure it's happening on Android too but I don't have one to test with, I cannot replicate when I'm not on a mobile device) and refresh the page it will connect correctly and then at random on a page refresh or even sometimes on a new page load I will see in the log that it connected twice at the same time which causes the page to hang on the socket.io request
and because it hangs on that request the other requests I do will be stuck waiting for that one to complete and the page will never load.
Upvotes: 1
Views: 3299
Reputation: 149
I solved by doing this on the client
var socket = io.connect('http://#{ip}:3000',{reconnection:false});
Upvotes: 1