socket.io emits multiple times

后端 未结 3 1665
天命终不由人
天命终不由人 2021-01-04 06:53

I have got a very basic example. This question has been asked previously multiple times in stack overflow itself but I could not get the right answer so I am going with this

3条回答
  •  礼貌的吻别
    2021-01-04 07:24

    I think you are adding more and more listeners to 'result' each call you make to check.

    First time click -> call 1 console.log from call 1 listener

    Second time click -> call 1 console.log from call 1 listener + call 2 console.log from call 1 listener + call 2 console.log from call 2 listener

    Third time -> The previous logs + call 3 console.log from call 1 listener + call 3 console.log from call 2 listener and call 3 console.log from call 3 listener.

    Try putting the listener for 'result' out of the function:

    
     
        
        
        
     
    
    

提交回复
热议问题