Skip to content

A simple TCP relay mechanism for NAT traversal built using Node.js

License

Notifications You must be signed in to change notification settings

shanghaikid/node-tcp-relay

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

These TCP relay scripts can be used to expose any TCP/IP service running behind a NAT. This includes services that use HTTP, SSH, and so on. It is composed of two Node.js scripts - relayc.js and relays.js. The latest source code is available at GitHub. Use npm to install.

The relays.js script is meant to be executed on the server visible on the internet as follows

tcprelays --relayPort port --servicePort port

relayPort is the port where the relay server will listen for incoming connections from the relay client. servicePort is the port where external clients can connect to the service exposed through the relay.

The relayc.js script is meant to be executed on a machine behind a NAT as follows

tcprelayc --host host --port port --relayHost host --relayPort port [--numConn count]

host is any server visible to the machine behind the NAT, it can also be localhost. port is the port of the service you want to expose through the relay. relayServer is the host or IP address of the server visible on the internet, and already executing the relays.js script. relayPort is the port where this script will connect with the relay server. numConn is the number of unused sockets relay client maintains with the relay server. As soon as it detects data activity on a socket, relay client establishes another connection.

If you're using HTTP/S, use a reverse proxy such as http-proxy, between the relay client and the local service e.g.

var httpProxy = require('http-proxy');
httpProxy.createProxyServer({target:'http://host:port'}).listen(port);

One external module is used in these scripts to parse commands line options. It can be installed using npm as follows

sudo npm -g install optimist@latest

About

A simple TCP relay mechanism for NAT traversal built using Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%