NodeJS - create simple forwarding server
I'm trying to create a simple nodejs server to server program.
Here's what I'm trying to achieve:
-----------¦remote¦-----satellite link-----¦core¦---------
port 6999 port 7000 port 6999
I need to write node.js code for both 'remote' and 'core'.
Here's what I have sofar (I'm a very confused now...):
//remote.js
var util=require('util');
var net=require('net');
var input=net.createServer(function(inputStream){
inputStream.on('data', function(data) {
util.puts(data);
});
var output=net.createServer(function(outputStream) {
outputStream.pipe(inputStream, {end: false});
outputStream.on('data',function(dta){
util.puts(dta);
});
});
output.listen(7000, '172.16.1.224');
});
input.listen(6999, '172.16.1.224');
Once I have these two forwarding modules (remote and core) up-and-running, I'm hoping to do some packet inspection...
Many thanks in a开发者_JS百科dvance,
you need to call createConnection for output stream. Look at my port forwarding code here
You can simply define input and output as two connections, like so.
net.createServer(function(from) {
var to = net.createConnection({
host: addr.to[2],
port: addr.to[3]
});
from.pipe(to);
to.pipe(from);
}).listen(addr.from[3], addr.from[2]);
See Node.js - forward all traffic from port A to port B
精彩评论