Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Created August 16, 2013 21:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TooTallNate/6253581 to your computer and use it in GitHub Desktop.
Save TooTallNate/6253581 to your computer and use it in GitHub Desktop.
Establishing a WebSocket connection to "ws://echo.websocket.org" over a Tor SOCKS proxy. Currently depends on pull request: https://github.com/einaros/ws/pull/220
var WebSocket = require('ws');
var SocksProxyAgent = require('socks-proxy-agent');
var url = process.argv[2] || 'ws://echo.websocket.org';
var agent = new SocksProxyAgent('socks://127.0.0.1:9050');
var opts = {};
opts.agent = agent;
var socket = new WebSocket(url, opts);
socket.on('open', function () {
console.log('"open" event!');
socket.send('something');
});
var i = 0;
socket.on('message', function (data, flags) {
console.log('got data!: %j', data);
socket.send('something ' + (i++));
});
@nifflin
Copy link

nifflin commented Apr 16, 2015

i use 9150 port, chrome could use '127.0.0.1:9150' as socks5 proxy and access web and deep web through TOR.

i am searching the solution which could make tor a websocket proxy server, i find this project, i added code into this js file:
socket.on('error', function (evt) {
console.log('%s', evt);
});

Then i run this js file by "node websocket-over-tor.js", but the cmd prints nothing. Then i tried 9050, the log is "Error: Socket Closed".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment