Socket.io message event firing multiple times

后端 未结 4 714
囚心锁ツ
囚心锁ツ 2021-01-02 10:11

I was trying to learn node and started creating a mashup with socket.io The message transportation have begin but I have run into some trouble.

The message event is

4条回答
  •  执念已碎
    2021-01-02 10:51

    So I had the same problem. The solution is to close all your listeners on the socket.on('disconnect') event, this is what my code looks like -

     socket.on('disconnect', function () {
                    socket.removeAllListeners('send message');
                    socket.removeAllListeners('disconnect');
                    io.removeAllListeners('connection');
                });
    

    Might not need to call it on disconnect, not sure but I do it anyway.

提交回复
热议问题