Sure: simply,
keep your socket connections in your app.js or server.js file.
simply follow the code:
var http = require('http').Server(app);
var io = require('socket.io')(http);
now start the connection like:
io.on('connection', function(socket){
console.log("A user connected");
}):
whenever you run the server file, "a user connected" will be printed. means, one client has connected to the server.
to disconnect to the server:
io.on('connection', function(socket){
console.log("A user connected");
socket.on('disconnect',function(){
console.log("a user disconnected");
});
}):
now you are ready to send a message to all who are connected to the server:
socket.on('chat message', function(data){
socket.emit('chat message', msg);
});
If you want send a message to all exclude sender:
socket.on('chat message', function(data){
io.broadcast.emit('chat message', msg);
});
For more reference: Send response to all clients except sender (Socket.io)
I hope u got an idea on it.!! Good luck