Socket.io message event firing multiple times

后端 未结 4 690
囚心锁ツ
囚心锁ツ 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:52

    The whole part of socket.io code has to go outside external.chat function. Socket IO has to bind with the http/app server, you should not handle it within each request.

    the messages are firing the number of times = the sequence of connection of the client

    What essentially happening is, each time a new request arrives you are registering a event handler for message, hence it is fired as many times as the you have accessed chat URL.

    io.socket.on('message', function (data) {...})
    

提交回复
热议问题