MERN APP with Socket.io deployed on render not working

This is my server side code for socket intialization
const { createServer } = require(“http”);
const { Server } = require(“socket.io”);

const httpServer = createServer(app);
const io = new Server(httpServer, {
cors: {
origin: “https://ui-url”,
methods: [“GET”, “POST”],
},
});

httpServer.listen(3000);

This is my client side code for connecting to socket
useEffect(() => {

const s = io('https://backend-url.com');
setSocket(s);
console.log("socket", s);
return () => {
  s.disconnect();
};

}, );

→ I get this error in my browser console, not able to establish, the socket connection ,can anyone help?
WebSocket connection to ‘wss://backend-url.com/socket.io/?EIO=4&transport=websocket’ failed:

Hi Krishanu,

I’d suggest deploying this demo app to use as a reference implementation and then adapting it to mimic what exactly you may be facing with your service. https://github.com/socketio/chat-example

Regards,

Matt

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