websocket client doesn't work

Hi, I'm trying to create a websocket client to connect to binance but I can't get it to work. export default { async fetch(request) { const res = await fetch("wss://stream.binance.com:9443/ws/BTCUSDT@depth@1000ms", { headers: { Upgrade: "websocket" }, }); const webSocket = res.webSocket; webSocket.accept(); webSocket.addEventListener("message", (event) => { console.log(event.data); }); webSocket.send("Hello!"); // Above listener logs "Hello!" return new Response(); }, }; kj/async-io-win32.c++:982: warning: Bind address resolved to multiple addresses. Fetch API cannot load: wss://stream.binance.com:9443/ws/BTCUSDT@depth@1000ms what am i doing wrong? thanks
6 Replies
norelock
norelock13mo ago
Why you're connecting using Fetch??? are you new to coding?
TrueCrime
TrueCrimeOP13mo ago
example in cloudflare
No description
norelock
norelock13mo ago
that's not how you do ws connection even exactly in JS that's for cf worker nor the js also i'm 100% sure that binance dosen't support cloudflare workers connection to it
TrueCrime
TrueCrimeOP13mo ago
exactly that, I need to connect in cf worker
norelock
norelock13mo ago
now i'm busy so i'm not able to help atm.
TrueCrime
TrueCrimeOP13mo ago
ok thanks anyway
Want results from more Discord servers?
Add your server