axon icon indicating copy to clipboard operation
axon copied to clipboard

channel socket type

Open tj opened this issue 12 years ago • 0 comments

multiplexed streams.

write end:

var axon = require('..');
var fs = require('fs');

var c = axon.socket('channel');

c.bind(3000);

var files = [
  'lib/sockets/channel.js',
  'lib/sockets/pub.js',
  'lib/sockets/sub.js',
  'lib/sockets/pull.js',
  'lib/sockets/push.js'
]

files.forEach(function(file){
  var f = fs.createReadStream(file);
  var s = c.stream();
  f.pipe(s);
});

read end:


var axon = require('..');

var c = axon.socket('channel');

c.connect(3000);

c.on('stream', function(s){
  console.log('stream %s', s.id);

  s.on('data', function(msg){
    console.log('stream %s -> %s', s.id, msg.length);
  });

  s.on('end', function(){
    console.log('stream %s ended', s.id);
  });
});

got part of this going in add/channels, but it would be nice to have it bi-directional, also need to fix the stream implementation plumbing, but we'll have to refactor for 0.10.x with the less shitty stream implementation anyway so no point jumping through hoops right now for the old version

tj avatar Mar 23 '13 20:03 tj