comet.io
Lightweight comet server & client for Node.js
Server
var app = require('http').createServer(handler);
var file = new(require('node-static').Server)(__dirname + '/web', {});
var comet = require('../lib/comet.io.js').createServer();
app.listen(8000);
function handler(request, response) {
request.on('end', function() {
if (!comet.serve(request, response)) {
file.serve(request, response, function(err, res) {
if (err) { console.log(err); }
});
}
});
}
comet.on('connection', function (socket) {
socket.emit('test.message', { something:'any json object here' });
socket.on('test.response', function(data) {
});
});
Client
socket = comet.connect();
socket.on('connect', function() {
}).on('test.message', function (data) {
socket.emit('test.response', { something:'any json object' });
});