client --> proxy --> remote --> proxy --> client
Файл proxy.js
var net = require('net');
var LOCAL_PORT = 8080
, LOCAL_ADDR = '127.0.0.1'
, REMOTE_PORT = 80
, REMOTE_ADDR = 'google.com';
var server = net.createServer(function (socket) {
socket.on('data', function (data) {
console.log('------- START -------');
console.log('<< From client to proxy ', data.toString());
var serviceSocket = new net.Socket();
serviceSocket.connect(REMOTE_PORT, REMOTE_ADDR, function () {
console.log('>> From proxy to remote', data.toString());
serviceSocket.write(data);
});
serviceSocket.on('data', function (data) {
console.log('<< From remote to proxy', data.toString());
socket.write(data);
console.log('>> From proxy to client', data.toString());
});
serviceSocket.on('error', function () {throw error;});
});
});
server.listen(LOCAL_PORT, LOCAL_ADDR, function () {
console.log('TCP server accepting connection on port: ' + LOCAL_ADDR + ':' + LOCAL_PORT);
});
Комментариев нет:
Отправить комментарий