Trouble with websockets

Hello, I am facing difficulty to setting up a websocket server. The project keeps timing out.

my project can be found here.

my code

const WebSocket = require("ws");

const wsServer = new WebSocket("wss://websocket-server-yosh.glitch.me"); //new WebSocket.Server({ port: PORT });

let bb = 0;

wsServer.on("connection", function (socket) {
  bb++;
  socket.on("message", function (msg) {
    console.log("Received message from client: " + msg);

    // Broadcast that message to all connected clients
    wsServer.clients.forEach(function (client) {
      client.send(msg);
    });
  });
});

Thanks in advance

Even with a working wzz url it no work

Any help would be appreciated :pensive:

What do you want to do with this project? I only see the server code. If you want to connect to an external server then it’s ok. If you want to make a full stack all like a chat app, then you need to host the client too

I want it to only connect to an external server, but im having difficulty with that.

Just to clarify, if you’re working only with nodejs backend, you won’t see anything on the preview window.

Can you copy the error on the log window?

events.js:173
      throw er; // Unhandled 'error' event
      ^
Error: Unexpected server response: 404
    at ClientRequest.<anonymous> (/rbd/pnpm-volume/948802c6-3236-4c57-b9e1-5c9a8ee351a2/node_modules/.registry.npmjs.org/ws/7.4.3/node_modules/ws/lib/websocket.js:604:7)
    at ClientRequest.emit (events.js:196:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:565:23)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:116:17)
    at TLSSocket.socketOnData (_http_client.js:452:22)
    at TLSSocket.emit (events.js:196:13)
    at addChunk (_stream_readable.js:290:12)
    at readableAddChunk (_stream_readable.js:271:11)
    at TLSSocket.Readable.push (_stream_readable.js:226:10)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:166:17)
Emitted 'error' event at:
    at abortHandshake (/rbd/pnpm-volume/948802c6-3236-4c57-b9e1-5c9a8ee351a2/node_modules/.registry.npmjs.org/ws/7.4.3/node_modules/ws/lib/websocket.js:722:15)
    at ClientRequest.<anonymous> (/rbd/pnpm-volume/948802c6-3236-4c57-b9e1-5c9a8ee351a2/node_modules/.registry.npmjs.org/ws/7.4.3/node_modules/ws/lib/websocket.js:604:7)
    [... lines matching original stack trace ...]
    at TLSSocket.Readable.push (_stream_readable.js:226:10)