I'm trying to emit an event from my server to a client when a client clicks a button. The issue I'm having is that my client side code is getting executed multiple times for each time my server emits an event. How can I ensure that my client-side code fires only 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);
});
In reading the Node documentation, it seems that I might need to remove event listeners, so that clientFunc is fired only once per event?