Created
January 28, 2012 14:43
-
-
Save gautamrege/1694570 to your computer and use it in GitHub Desktop.
Notification node server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can we get this using another js function ?