0

Im trying programmatically create multiple websocket connections to my server where each websocket uses a different socks5 proxy. I have not found a way to create a websocket connection, Ive seen that websocket servers through a proxy exist but not the other way around.

I serached for days to no avail; Ive found no sources on how to do such things.

DrakoHyena
  • 47
  • 7

1 Answers1

0

Ive found a solution. I was originally trying to use HTTP/HTTPS proxies which failed every single time, however I tried SOCK5 proxies and.. it worked flawlessly. Here is some modified code taken from the githubs page of socks-proxy-agent, the proxy used here is a free one from a proxy list. https://github.com/TooTallNate/proxy-agents/tree/main/packages/socks-proxy-agent

let WebSocket = require('ws').WebSocket;
let SocksProxyAgent = require("socks-proxy-agent").SocksProxyAgent;

const agent = new SocksProxyAgent(
    'socks5://192.252.216.81:4145'
);

var socket = new WebSocket('ws://echo.websocket.events', { agent });

socket.on('open', function () {
    console.log('"open" event!');
    socket.send('hello world');
});

socket.on('message', function (data, flags) {
    console.log('"message" event! %j %j', data, flags);
    socket.close();
});

Result:

"open" event!
"message" event! {"type":"Buffer","data":[101,99,104,111,46,119,101,98,115,111,99,107,101,116,46,101,118,101,110,116,115,32,115,112,111,110,115,111,114,101,100,32,98,121,32,76,111,98,46,99,111,109]} false
"message" event! {"type":"Buffer","data":[104,101,108,108,111,32,119,111,114,108,100]} false
DrakoHyena
  • 47
  • 7