Preventing Socket.io from firing multiple times for each event

I am trying to send an event from my server to the client when the client clicks on a button. The problem I'm running into is that my client code gets executed multiple times for every time my server fires an event. How can I ensure that my client code only fires once for each event emitted by the server?

My client code looks like this:

socket.on('data', function(data) {   
  $('.button').on('click, function() {
    clientFunc(data)
  });
});

      

My server code looks like this:

serverFunc(json, function(data) {
  socket.emit('data', data);
});

      

When reading the Node documentation, it seems like I might need to remove event listeners so that it clientFunc

only fires once per event?

+3
node.js socket.io


source to share


No one has answered this question yet

Check out similar questions:

2201
How do you decide when to use Node.js?
ten
socket.io - works for the first time, not the second time
8
Socket.io fires multiple events
2
IO socket event fired multiple times by NodeJS
2
socket.io Emit events that fire multiple times
1
Why is my Socket.io event firing multiple times?
1
Socket.io fires callback function multiple times
0
start socket.io connect with multiple events
0
Send JSON value to server using Socket.io from jQuery
0
How does socket.io on the client listen for events coming from the server?



All Articles
Loading...
X
Show
Funny
Dev
Pics