开发者

Node.js TCP forwarder

I have the following simple NodeJS script and want to modify it slightly....

var sys = require( 'sys' ), net = require( 'net' );

var outputserver = net.createServer( function( stre开发者_StackOverflow社区am ) {
    stream.addListener( 'data', function( data ) {
        sys.puts( data );
        //Want to output anything from the clientserver data here
    });
}).listen( 7001, 'localhost' );

var clientserver = net.createServer( function( stream ) {
    stream.addListener( 'data', function( data ) {
        sys.puts( data );

    });
}).listen( 7000, 'localhost' );

I need anything coming in from the "clientserver" to be output to the "outputserver" stream. There will be 50-60 clients connecting to the the "clientserver"


This should work:

var util = require('util'), net = require('net');
var outServer = net.createServer(function(outStream) {
  outStream.on('data', function(data) {
    util.puts(data);
  });
  var inServer = net.createServer(function(inStream) {
    inStream.pipe(outStream, {end: false});
  });
  inServer.listen(7001, 'localhost');
});
outServer.listen(7000, 'localhost');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜