0

I have a browser, which connects to server using socket.io with transport as websocket only.

I validate all socket connecting to my server, using simple logic and is working fine.

Update-1

Now the problem occur when Internet fluctuates, browser is creating many websocket connection. (Issue similar to https://github.com/socketio/socket.io/issues/430)

As application requires one connection per browser and thus except one all other socket are being invalidated by validation code. But when I disconnect a invalidated socket all sockets are being disconnecting.

Simplified Code

const soredis = require('socket.io-redis');
const io = require('socket.io')(3000);

io.adapter(soredis({host: localhost, port: 6379}));

io.sockets.on('connection', function(socket) {

  setTimeout(function () {
    getSocket(socket.id, (err, res) => { //get data from redis
      if (err) { //If not found in redis
        socket.disconnect();
        return;
      }
    });
  }, 15000);


  socket.on('register', function(data, cb) {
    if (!data.key) {      
       return cb("Error");
    }
    saveSocket(socket.id); //save to redis
    return cb();  
  });

});

Any possible reason why and how to resolve the same??

Anuj Nautiyal
  • 599
  • 1
  • 4
  • 11
  • Please add the code you are using to disconnect – gnuns Aug 31 '17 at 12:52
  • Why are you validating in a 15 second timeout? I would think you'd want to use socket.io middleware to validate live, rather than after a long delay. – jfriend00 Aug 31 '17 at 20:20
  • After socket connects i am validating through register message from client. And if register failed or no such register received from the client, Server is forcefully disconnected after 15 second. This disconnect message to a single socket is disconnecting all socket both registered and non-registered. – Anuj Nautiyal Sep 01 '17 at 05:57

0 Answers0