node-tcp-proxy
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"main": "index.js", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -0,13 +1,22 @@ | ||
# node-tcp-proxy | ||
A simple TCP proxy that may be used to access a service on another network. An extensible replacement for socat when used thus | ||
``` | ||
```bash | ||
socat TCP-LISTEN:port1,fork TCP:host:port2 | ||
``` | ||
port1 is where socat listens for incoming requests. host and port2 are the host and port where the actual service is listening at. | ||
`port1` is where socat listens for incoming requests. `host` and `port2` are the host and port where the actual service is listening at. | ||
To achieve the same with node-tcp-proxy | ||
```bash | ||
node tcpproxy.js --proxyPort port1 [--hostname [IP]] --serviceHost host --servicePort port2 [--q] | ||
``` | ||
node tcpproxy.js --proxyPort [port1] --serviceHost [host] --servicePort [port2] [--q] | ||
``` | ||
Install node-tcp-proxy from [npm](https://www.npmjs.com/package/node-tcp-proxy) | ||
Optionally, `hostname` specifies the IP address to listen at. Node.js listens on unspecified IPv6 address `::` by default. | ||
## npm | ||
Install node-tcp-proxy from [npm](https://www.npmjs.com/package/node-tcp-proxy), thus | ||
``` | ||
@@ -17,3 +26,6 @@ sudo npm install -g node-tcp-proxy | ||
To create a proxy in your own code. | ||
## Programming Interface | ||
To create a proxy in your own code | ||
```javascript | ||
@@ -25,2 +37,3 @@ var proxy = require("node-tcp-proxy"); | ||
To end the proxy | ||
```javascript | ||
@@ -30,2 +43,2 @@ newProxy.end(); | ||
Console output may be silenced through an optional `{quiet: true}` fourth `createProxy` argument. | ||
`hostname` can be provided through an optional fourth parameter e.g. `{hostname: 0.0.0.0}` to `createProxy`. Console output may be silenced by using `quiet: true` e.g. `{hostname: 0.0.0.0, quiet: true}`. |
@@ -5,3 +5,3 @@ #!/usr/bin/env node | ||
var argv = require("optimist") | ||
.usage('Usage: $0 --proxyPort [port] --serviceHost [host] --servicePort [port] [--q]') | ||
.usage('Usage: $0 --proxyPort [port] [--hostname [IP]] --serviceHost [host] --servicePort [port] [--q]') | ||
.demand(['proxyPort', 'serviceHost', 'servicePort']) | ||
@@ -12,2 +12,3 @@ .boolean('q') | ||
var options = { | ||
hostname: argv.hostname, | ||
quiet: argv.q | ||
@@ -14,0 +15,0 @@ }; |
var net = require("net"); | ||
module.exports = { | ||
createProxy: function(proxyPort, serviceHost, servicePort, options) { | ||
return new Proxy(proxyPort, serviceHost, servicePort, options); | ||
} | ||
} | ||
function uniqueKey(socket) { | ||
@@ -39,14 +45,11 @@ var key = socket.remoteAddress + ':' + socket.remotePort; | ||
} | ||
serviceSocket.on("data", function (data) { | ||
proxySocket.write(data); | ||
}); | ||
serviceSocket.on("close", function (had_error) { | ||
proxy.log("service socket closed"); | ||
proxy.log(" ending proxy socket"); | ||
proxySocket.destroy(); | ||
}); | ||
}); | ||
serviceSocket.on("data", function (data) { | ||
proxySocket.write(data); | ||
}); | ||
serviceSocket.on("close", function (had_error) { | ||
proxy.log("service socket closed"); | ||
proxy.log(" ending proxy socket"); | ||
proxySocket.destroy(); | ||
}); | ||
serviceSocket.on("error", function (e) { | ||
@@ -59,8 +62,6 @@ proxy.log("service socket error"); | ||
proxySocket.on("error", function (e) { | ||
proxy.log("proxy socket error"); | ||
proxy.log(e); | ||
}); | ||
}); | ||
proxySocket.on("data", function (data) { | ||
@@ -73,3 +74,2 @@ if (connected) { | ||
}); | ||
proxySocket.on("close", function (had_error) { | ||
@@ -80,3 +80,3 @@ delete proxy.proxySockets[uniqueKey(proxySocket)]; | ||
}).listen(proxy.proxyPort); | ||
}).listen(proxy.proxyPort, proxy.options.hostname); | ||
} | ||
@@ -90,2 +90,3 @@ | ||
} | ||
this.server.unref(); | ||
} | ||
@@ -101,5 +102,1 @@ | ||
} | ||
exports.createProxy = function(proxyPort, serviceHost, servicePort, options) { | ||
return new Proxy(proxyPort, serviceHost, servicePort, options); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6144
103
42