The bottom line is, there is a banal websocket server on nodejs

var io = require('socket.io').listen(httpsServer); io.sockets.on('connection', function(socket) { var ID = (socket.id).toString(); console.log(socket); socket.on('message', function(msg) { socket.send(msg); }); socket.on('disconnect', function() { console.log(ID+" disconnect"); }); }); 

And the banal client

 var socket = io.connect('https://********:8443'); socket.on('connect', function () { socket.on('message', function (msg) { console.log(msg); }); }); 

When restarting nodejs on the server, the client reconnects (if the page was not reloaded), but the previous connection remains. So when sending a message to socket.send ({test: ''}); not one comes back, but n is the number of messages. How to fix?

    1 answer 1

     var socket = io.connect('https://********:8443'); socket.once('connect', function () { socket.on('message', function (msg) { console.log(msg); }); }); 

    Use once instead of one