Created
July 7, 2011 19:54
-
-
Save alessioalex/1070395 to your computer and use it in GitHub Desktop.
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 http = require('http'), | |
faye = require('faye'), | |
fs = require('fs'), | |
path = require('path'); | |
var bayeux = new faye.NodeAdapter({ | |
mount: '/faye', | |
timeout: 45 | |
}); | |
var PUBLIC_DIR = path.dirname(__filename); | |
// Handle non-Bayeux requests | |
var server = http.createServer(function(req, res) { | |
var path = (req.url === '/') ? '/index.html' : req.url; | |
fs.readFile(PUBLIC_DIR + path, function(err, content) { | |
var status = err ? 404 : 200; | |
res.writeHead(status, {'Content-Type': 'text/html'}); | |
res.write(content || 'Not found'); | |
res.end(); | |
}); | |
}); | |
bayeux.attach(server); | |
server.listen(8000); | |
var client = new Faye.Client('http://localhost:8000/faye'); | |
client.subscribe('/messages', function(message) { | |
console.log('SS: ' + message.text); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment