Ad

Socket.io Does Not Close Previous Connection

- 1 answer

we have this socket.io serverside that on auth joins the user in the rooms he is in, but on disconnect it seems like it does not really disconnect, because on a new connect i get 2 connections, seen in screenshot. Also included is the disconnect code part.

connection part:

 io.on("connection", function(socket) {
    console.log("connected");
    console.log("user connected with " + socket.id);

disconnect part:

 socket.on("disconnect", function() {
  socket.removeAllListeners();
  if (socket.auth) {
    socket.groups.forEach(group => {
      console.log("left " + group.chatGroupID);
      socket.leave(group.chatGroupID);
    });
  }

  delete socket[socket.id];
  socket.disconnect(true);
  console.log(socket.disconnected);
  console.info("disconnected user (id=" + socket.id + ").");
});

server printout:

Server log

Ad

Answer

somehow i globbed all files in my folder sockets and thus nested my sockets which caused this weird behavior

Ad
source: stackoverflow.com
Ad