I have new to socket.io and have a plain chat application.
Its a multi user application where chat messages are emitted to all connected users.
Below is my code for server side. Where chat message is the event fired and subscribed to for broadcast of messages
Now my question is, is the code correct ? Specially the disconnect part. Do i have to remove the subscribers or listeners which have been subsrcibed with chat message event on disconnect ?. is this a leak if i don't remove the listeners?
var server = app.listen(3006);
console.log('listening on port 3006');
//socket io event listening
var io = require('socket.io').listen(server);
io.on('connection', function(socket) {
console.log('a user connected');
socket.on('disconnect', function() {
console.log('user disconnected');
});
socket.on('chat message', function(msg) {
console.log(msg);
io.emit('chat message', msg);
});
});