Skip to content

Instantly share code, notes, and snippets.

@gautamrege
Created January 28, 2012 14:43
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save gautamrege/1694570 to your computer and use it in GitHub Desktop.
Save gautamrege/1694570 to your computer and use it in GitHub Desktop.
Notification node server
var express = require('express')
, app = express.createServer()
, io = require('socket.io').listen(app);
app.use(express.bodyParser());
app.listen(13002);
var connections = {}
/********** express.js routes ************/
app.get('/', function (req, res) {
res.send(404);
});
app.post('/message/:action/:to', function (req, res) {
target = connections[req.params.to]
if (target) {
connections[req.params.to].emit(req.params.action, req.body);
res.send(200);
}
else
res.send(404);
});
/********** socket.io work ***************/
io.sockets.on('connection', function(socket) {
socket.on('username', function(username) {
connections[username] = socket;
});
});
@chanakaDe
Copy link

How can we get this using another js function ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment