Failed WebSocket connection

I am trying to connect to the websocket that I have deployed on my service but it never ends up connecting…

View.308bf5e6.js:1 WebSocket connection to ‘wss://heres-my-server.onrender.com/socket.io/?EIO=4&transport=websocket&force_ssl=true’ failed:

I always get that error… I am using an application in NodeJS where I have port 3000 for common requests and port 5000 for websocket…

// Starting the server
const server = app.listen(app.get("port"), () => {
  console.log(`Server is running on: ${app.get("port")}`);
});

// Websocket
const { Server } = require("socket.io");
global.io = new Server(5000);

global.io.use((socket, next) => {
  if (tokenValidation.socket(socket.handshake.auth)) {
    next();
  } else {
    next(new Error("NOT_AUTHENTICATED"));
  }
});

global.io.on("connection", (socket) => {
  // notify existing users
  console.log("Someone connected");
});

Hi there,
A webservice can only expose a single port so you can’t use 3000 and 5000,

Regards,

John B

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.