Skip to content
No description or website provided.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
.jshintignore
.jshintrc
.npmignore
.travis.yml
Gruntfile.js
LICENSE
README.md
index.js
package.json

README.md

conducto

Node.js framework, REST and realtime

Build Status Dependency Status devDependency Status

Server
var conducto = require('conducto');

var server = new conducto.Server();

//middleware
server.use(function(req, res, next)
  if (req.method !== 'sum')
    return next();

  //payload doesn't comply, send an error to the client
  if (!req.payload || !Array.isArray(req.payload))
    return res('Payload must be an array.');


  var sum = 0;
  for (var i = 0; i < payload.length; i++) {
    sum += payload[i];
  }

  //send the result to the client
  res(null, sum);
});

//broadcast a message to all connected clients
server.broadcast({method: 'foo', payload: 'bar'});

server.listen(3000);
Client
var client = new conducto.Client();

client.open({secure: false, hostname: 'localhost', port: 3000});

//wait for socket to open
client.on('open', function() {

 /*
  * first argument is the method name,
  * second the payload, optional
  * third is a callback, optional
  */


  client.send('sum', 'foo', function(err, res) {
    //an err will be received as the payload doesn't comply
    console.log(err || res);
    //'Payload must be an array.'
  });

  client.send('sum', [0, 1, 2, 3], function(err, res) {
    console.log(err || res);
    //6
  });
});
Something went wrong with that request. Please try again.