I am unable to connect to my websocket the error i get is Failed to execute ‘send’ on ‘WebSocket’: Still in CONNECT
i am trying to send a message to my websocket and it won’t load
const socket = new WebSocket('ws://billowing-thunder-1177.fly.dev');
socket.addEventListener('open', function (event) {
console.log('Connected to WS Server')
});
socket.send("Hello");
const express = require('express')
const app = express()
const server = require('http').createServer(app);
const WebSocket = require('ws');
const port = process.env.PORT || 3000;
const wss = new WebSocket.Server({ server:server });
wss.on('connection', function connection(ws) {
console.log('A new client Connected!');
ws.send('Welcome New Client!');
ws.on('message', function incoming(message) {
console.log('received: %s', message);
wss.clients.forEach(function each(client) {
if (client !== ws && client.readyState === WebSocket.OPEN) {
client.send(message);
}
});
});
});
app.listen(port, () => console.log(`HelloNode app listening on port ${port}!`))
it works on localhost but not on fly.io