3.2.7 • Published 5 months ago
@casual-simulation/tunnel v3.2.7
Tunnel
A WebSockets-based TCP tunnel library and CLI.
Allows the creation of forward and reverse tunnels to get around firewalls and NAT.
CLI
Installation
$ npm install -g @casual-simulation/tunnel
Usage
Starting a tunnel server on port 80
$ tunnel serve 80
Open a tunnel to my_server_ip
on port 80 that pipes port 8080 to example.com
on port 80
$ tunnel connect ws://my_server_ip:80 --forward 8080 --host example.com --port 80
Open a reverse tunnel to my_server_ip
on port 80 that pipes port 8080 on the tunnel server to 127.0.0.1
on port 3000 in the local network.
$ tunnel connect ws://my_server_ip:80 --reverse 8080 --host 127.0.0.1 --port 3000
Library
Installation
$ npm install @casual-simulation/tunnel
Usage
Starting a tunnel server
import { WebSocketServer } from '@casual-simulation/tunnel';
import { Server as HttpServer } from 'http';
function start() {
// Create a HTTP Server
const http = new HttpServer();
// Create a WebSocket tunnel server that listens for
// requests on the given HTTP server.
const tunnel = new WebSocketServer(http);
tunnel.listen();
// Start listening for HTTP requests on port 8080
http.listen(8080);
}
Authorizing tunnel requests
// the acceptTunnel property is a filter function
// which is called in order to determine whether to accept
// a tunnel connection request from a client.
tunnel.acceptTunnel = request => {
if (request.authorization === 'password') {
return true;
} else {
return false;
}
};
Connecting to a tunnel server
import { WebSocketClient } from '@casual-simulation/tunnel';
// Create a client that connects to the server at my_server_address
const client = new WebSocketClient('ws://my_server_address');
// Get an observable that opens a tunnel
// connection to the server to connect to
// example.com on port 80 whenever a connection
// is made to port 8080 on the local
// host.
const messages = client.open({
direction: 'forward',
token: 'password',
remoteHost: 'example.com',
remotePort: 80,
localPort: 8080,
});
// Start listening
const subscription = messages.subscribe(
m => console.log(m),
err => console.error(err)
);
// You can stop listening by disposing of the subscription
subscription.unsubscribe();
3.2.7
5 months ago
3.2.7-alpha.7293404763
5 months ago
3.2.7-alpha.7280400706
5 months ago
3.2.7-alpha.7278679536
5 months ago
3.2.7-alpha.7203795135
5 months ago
3.1.28
1 year ago
3.1.14-alpha.3633552440
1 year ago
3.1.11
1 year ago
3.1.12-alpha.3578187535
1 year ago
3.1.11-alpha.3483057957
1 year ago
3.1.14-alpha.3661157217
1 year ago
3.1.11-alpha.3500062488
1 year ago
3.1.11-alpha.3500879217
1 year ago
3.0.14-alpha.2511011009
2 years ago
3.0.14-alpha.2505160566
2 years ago
3.0.15-alpha.2537844219
2 years ago
3.0.14
2 years ago
3.0.14-alpha.2499890262
2 years ago
2.0.30
2 years ago
3.0.0
2 years ago
3.0.2-alpha.1884665520
2 years ago
3.0.0-alpha.1826142686
2 years ago
2.0.16
2 years ago
2.0.14
3 years ago
2.0.14-alpha.1392172559
3 years ago
2.0.2-alpha.984036479
3 years ago
2.0.2-alpha.983566027
3 years ago
2.0.2-alpha.981663424
3 years ago
2.0.2-alpha.981597206
3 years ago
2.0.2-alpha.979932941
3 years ago
2.0.2-alpha.973487792
3 years ago
2.0.2-alpha.972817819
3 years ago
2.0.2-alpha.972872148
3 years ago
2.0.2-alpha.972918106
3 years ago
2.0.0
3 years ago
1.5.0
3 years ago
1.4.7-alpha.33
3 years ago
1.4.7-alpha.32
3 years ago
1.4.3
3 years ago
1.2.1
4 years ago
1.0.24
4 years ago
1.0.0
4 years ago
0.11.20
4 years ago
0.11.17
4 years ago
0.11.0
5 years ago
0.10.0
5 years ago
0.9.38
5 years ago
0.9.37
5 years ago