Closed pinilpypinilpy closed 4 years ago
Can you show the exact code you're using?
sure: const WebSocket = require('ws'); var url = require('url'); var https = require('https'); var HttpsProxyAgent = require('https-proxy-agent'); var proxy = process.env.http_proxy || 'https://198.98.56.71:8080'; console.log('using proxy server %j', proxy); var endpoint = process.argv[2] || 'wss://echo.websocket.org/'; var parsed = url.parse(endpoint); console.log('attempting to connect to WebSocket %j', endpoint); var options = url.parse(proxy); var agent = new HttpsProxyAgent(options); const ws = new WebSocket('wss://echo.websocket.org/', { origin: 'https://websocket.org', agent: agent }); ws.on('open', function open() { console.log('connected'); ws.send(Date.now()); });
ws.on('close', function close() { console.log('disconnected'); });
ws.on('message', function incoming(data) {
console.log(Roundtrip time: ${Date.now() - data} ms
);
setTimeout(function timeout() { ws.send(Date.now()); }, 500); });
however, I've had a far better time with the socks proxy, so I think I'll use that instead. Also, I got the same error using the sample https code instead of ws
ok, I think it was because I put https instead of http, but that's kinda counter-intuitive, gotta say thanks for the quick response.
when using the sample code to connect to echo.websockets.org and an http proxy everything goes fine, but when attempting to use https and wss instead of ws, I get:
Thanks in advance