socket.io-client icon indicating copy to clipboard operation
socket.io-client copied to clipboard

Socketio connected successfully, but console says "WebSocket connection to "wss:.." failed

Open vincentsartoko opened this issue 2 years ago • 3 comments

The connection to the socket works, because here is my code (React):

socket.current = io("www.ohezo.com", { auth: { id } });
socket.current.on("open", () => {
    console.log("It worked");
}

Once the client receives something from the socket listener "open", it will no longer show the loading screen, but let's just put console.log for simplicity. Everything works fine, I opened another tab and I can send chat, friend requests, etc.

However, inside the console I got this error: image

If you have any clue on the error please let me know thank you!

vincentsartoko avatar Sep 03 '21 16:09 vincentsartoko

how to resolve this error

Stevenzwzhai avatar Sep 30 '21 09:09 Stevenzwzhai

@Stevenzwzhai you need to redirect the request to wss instead of http, are you using VPS?

vincentsartoko avatar Sep 30 '21 10:09 vincentsartoko

to resolve an error like that try:

  • commenting out server-side code like httpServer.on('upgrade', wsProxy.upgrade); and const wsProxy = app.use('/socket.io/', createProxyMiddleware({ ... }));, it may be a port conflict like mentioned here https://github.com/parcel-bundler/parcel/discussions/7071
  • if you're running an Express.js server check it's running on the same host httpServer.listen(process.env.PORT, process.env.NODE_ENV === "production" ? HOST_IP : '0.0.0.0');

ltfschoen avatar Feb 21 '23 20:02 ltfschoen

For future readers:

This might indicate that something between the server and your browser is preventing the WebSocket connection.

More information here: https://socket.io/docs/v4/troubleshooting-connection-issues/#problem-the-socket-is-stuck-in-http-long-polling

Please reopen if needed.

darrachequesne avatar Apr 11 '24 07:04 darrachequesne