项目作者: Defkil

项目描述 :
simple tcp proxy for nodejs
高级语言: JavaScript
项目地址: git://github.com/Defkil/tcp-proxy.git
创建时间: 2016-05-18T16:39:33Z
项目社区:https://github.com/Defkil/tcp-proxy

开源协议:

下载


NPM

NPM
Github
Docs
Build Status
Coverage Status
Known Vulnerabilities
dependencies Status

Simple TCP Proxy module for NodeJS

Require simple-tcp-proxy

  1. const SimpleTcpProxy = require('simple-tcp-proxy')

Create a proxy with a function

  1. const proxy = new SimpleTcpProxy({proxy:{host:'127.0.0.1', port:25565}, target:{host:'127.0.0.1', port:25566}});
  2. proxy.start(function(server, client){ // optional callback will be called with every new connection
  3. // object from proxy (tcp server)
  4. server.on('data', function(data){
  5. console.log(data);
  6. });
  7. // object from client (client to target server)
  8. client.on('data', function(data){
  9. console.log(data);
  10. });
  11. }, function(error){
  12. // optional error handler
  13. console.log(error);
  14. });
  15. console.log(proxy.status); // print proxy status (online/offline)
  16. console.log(proxy.client_con); // print an object with all connections
  17. console.log(proxy.socket) // print proxy server socket

one line proxy

  1. proxy.run({proxy:{host:'127.0.0.1', port:25565}, target:{host:'127.0.0.1', port:25566}})

all scripts in package.json are not available over npm only over github

changed to update 2.0.0

  1. // old (v1.0.0) version (won't work!)
  2. require('simple-tcp-proxy')({proxy: {}, target: {}}, ()=> {}, ()=> {})
  3. // new version
  4. require('simple-tcp-proxy').run({proxy: {}, target: {}}, ()=> {}, ()=> {})
  5. // or with a class
  6. const proxy = new require('simple-tcp-proxy')({proxy: {}, target: {}})
  7. proxy.start()