I\'m new to the node.js and socket.io scene, so this may be a simple fix... but here goes. I have the following POC for taking in messages via UDP and echoing them back to a br
As far as I can tell without having node to test on; you're not really interested in doing anything on socket.io connection events as long as the client doesn't send any data you need to handle, so you should be able to ignore them. What you want is only to receive UDP events and broadcast to all clients that are connected right then, which should be as simple as;
...
var io = require('socket.io').listen(server);
server.listen(12345); //tcp http listener
udpserver.on('message', function (msg, rinfo) {
io.sockets.emit('update', msg.toString());
});
Just for completeness; what your current code does is to add a new UDP message callback for every new socket.io connection. The callback broadcasts to all clients, which means that when the second client connects, all broadcasts will happen 2 times to all clients, for 3 clients 3 times to all clients etc. You only want to set the UDP message handler up once since it broadcasts to all connected clients anyway.