On the first click, my client outputs this:
Object {hello: "world"}
Then on the second click:
Object {hello: "world"}
Object {hello: "world"}
And the number of times the line is output for a click increases by one with subsequent click.
Client
var socket = io.connect('http://localhost');
$(document).on('click' , '#test', function(){
socket.emit('news', { my: 'data' });
socket.on('news', function (data) {
console.log(data);
});
});
Server
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
io.sockets.on('connection', function (socket) {
socket.on('news', function (data) {
socket.emit('news', { hello: 'world' });
console.log(data);
});
});