socket.io-client
socket.io-client copied to clipboard
Socketio connected successfully, but console says "WebSocket connection to "wss:.." failed
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:
If you have any clue on the error please let me know thank you!
how to resolve this error
@Stevenzwzhai you need to redirect the request to wss instead of http, are you using VPS?
to resolve an error like that try:
- commenting out server-side code like
httpServer.on('upgrade', wsProxy.upgrade);
andconst 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');
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.