public
Created

  • Download Gist
tcp_proxy.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
var net = require('net');
var sys = require('sys');
 
function repr(wot) {
sys.puts(sys.inspect(wot));
}
 
net.createServer(function (socket) {
//repr(socket);
client = net.createConnection(8888);
socket.setEncoding('utf-8');
client.setEncoding('utf-8');
 
socket.addListener("connect", function () {
sys.log("Connection from " + socket.remoteAddress+" Port: " + socket.remotePort);
});
client.addListener("data", function (data) {
sys.log("outgoing: " + data);
socket.write(data);
});
 
socket.addListener("data", function (data) {
sys.log("incoming: " + data);
client.write(data);
});
 
socket.addListener("end", function () {
sys.log("Connection from " + socket.remoteAddress+" Port: " + socket.remotePort +" has ended");
socket.end();
});
 
}).listen(9000);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.