Note that there are some explanatory texts on larger screens.

plurals
  1. POnode.js + socket.IO - socket not reconnecting?
    text
    copied!<p>I know socket.io has a built in feature for reconnecting and everything, however I don't think that it is working - as I have seen from others it's also not working for them either. </p> <p>If a user puts their computer to sleep, it disconnects them, and then when they open it back up they are no longer connected so they don't any of the notifications or anything until they refresh the page. Perhaps it's just something that I'm not doing correctly?</p> <pre><code>var io = require('socket.io').listen(8080); var users = {}; ////////////////USER CONNECTED///// console.log("Sever is now running"); io.sockets.on('connection', function (socket) { //Tell the client that they are connected socket.emit('connected'); //Once the users session is recieved socket.on('session', function (session) { //Add users to users variable users[socket.id] = {userID:session, socketID:socket}; //When user disconnects socket.on('disconnect', function () { //socket.socket.connect(); var count= 0; for(var key in users){ if(users[key].userID==session)++count; if(count== 2) break; } if(count== 1){ socket.broadcast.emit('disconnect', { data : session}); } //Remove users session id from users variable delete users[socket.id]; }); socket.on('error', function (err) { //socket.socket.connect(); }); </code></pre> <p><code>socket.emit("connection")</code> needs to be called when the user reconnects, or at least the events that happen in that event need to be called.</p> <p>Also <code>socket.socket.connect();</code> doesn't work, it returns with an error and it shuts the socket server down with an error of "connect doesn't exist".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload