Skip to content
Lightweight comet server/client for Node.js
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
README.md
package.json

README.md

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) {
  // do something when a client has connected
  socket.emit('test.message', { something:'any json object here' });

  socket.on('test.response', function(data) {
    // do something when it receives a message from client
  });
});

Client

  socket = comet.connect();
  socket.on('connect', function() {
    // do something when it's connected for the first time
  }).on('test.message', function (data) {
    // do something, such as sending an message to the server
    socket.emit('test.response', { something:'any json object' });
  });
You can’t perform that action at this time.