axon icon indicating copy to clipboard operation
axon copied to clipboard

Expose .createStream()

Open juliangruber opened this issue 13 years ago • 7 comments

I want to use axon with secure-peer for super easy security and thus need access to the raw stream. Any plans on doing this?

juliangruber avatar Nov 27 '12 06:11 juliangruber

Probably not, @visionmedia can correct me but exposing the stream (for the use of composing new streams) wouldn't really mesh well with the protocol, really even with the messaging paradigm in general because of the whole <length> + <body>.

gjohnson avatar Nov 29 '12 13:11 gjohnson

I dont recall us even having a .createStream() anywhere

tj avatar Nov 29 '12 19:11 tj

I just wondered if it would be possible. I want to use axon-rcp for auth stuff and thus need encryption, that's my use case...

juliangruber avatar Nov 29 '12 20:11 juliangruber

Yeah, I assumed @juliangruber meant add one to the api. Like mongoose or something, ala:

subSocket.stream().pipe(whatever);

Right?

gjohnson avatar Nov 29 '12 20:11 gjohnson

server:

var rpc = require('axon-rpc')
  , axon = require('axon')
  , rep = axon.socket('rep')
  , net = require('net');

var server = new rpc.Server(rep);

// instead of this: rep.bind(4000);

net.createServer(function (socket) {
  socket.pipe(server.createStream()).pipe(socket)
}).listen(4000)

client:

var rpc = require('axon-rpc')
  , axon = require('axon')
  , req = axon.socket('req')
  , net = require('net');

var client = new rpc.Client(req);
var clientStream = client.createStream();

// with the net module
clientStream.pipe(net.connect(4000)).pipe(clientStream());

// or with dominictarr's reconnect:
reconnect(function (stream) {
  clientStream.pipe(stream).pipe(clientStream)
}).connect(4000)

This way you make it transport agnostic and it will also work in the browser over websockets, or whatevs!

juliangruber avatar Nov 29 '12 20:11 juliangruber

im fine with it as long as:

  • a) we dont overly complicate internals to abstract out accepting socket connections etc
  • b) we dont change the existing default api
  • c) performance is retained

though personally there wouldn't really be many use-cases to use it for anything but regular tcp, not all transports have the same capabilities, via stdin etc would be leaky

tj avatar Nov 29 '12 20:11 tj

:+1:

CoderPuppy avatar Dec 17 '12 20:12 CoderPuppy