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
Why you're connecting using Fetch???
are you new to coding?
example in cloudflare
![No description](https://cdn.answeroverflow.com/1182893869675847712/Screenshot_4.png)
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
exactly that, I need to connect in cf worker
now i'm busy so i'm not able to help atm.
ok thanks anyway