Home /Archive by Category "NodeJs"

Broadcast Message using Node.js

Server Side Code [CHC_CODE]var app = require(‘./lib/express’)(); var http = require(‘http’).Server(app); var io = require(‘socket.io’)(http); app.get(‘/abc’, function(req, res){ res.end(‘Hello World\n’); }); io.on(‘connection’, function(socket){ console.log(‘user connected’); socket.on(‘setUserId’, function (data) { console.log(data); socket.broadcast.emit(‘updatedata’, { info: ‘Hi’+data }); socket.emit(‘updatedata’, { info: ‘Hi’+data }); }); }); http.listen(9000, function(){ console.log(‘listening on *:9000’); }); [/CHC_CODE]   Client Side Code Add Js … Continue reading