Search code examples
javascriptnode.jssocketswebsocketsocket.io

WebSocket connection to 'wss://******/socket.io/?EIO=4&transport=websocket&sid=T2Sf_4oNIisxKLwsAAAK' failed


I'm making a WebSocket connection with socket.io and when I log in, I get this error:

WebSocket connection to 'wss://******/socket.io/?EIO=4&transport=websocket&sid=T2Sf_4oNIisxKLwsAAAK' failed:websocket.js:54

enter image description here

But then the connection is established, although I'm not sure if it's done correctly. It hasn't caused me any issues, but that error always appears first when starting, and then everything works fine. But the thing is, once I'm logged in, everything seems to work just fine after the error. It's just that this error pops up at the beginning, and I want to make sure it won't cause any issues once it's in production. I'd really appreciate any help you can provide. Thanks a bunch in advance!

This is my server code with express:

const http = require('http');
const server = http.createServer(app);

const { Server } = require('socket.io')
const io = new Server(server)

This is my client code:

       var socket = io.(Config.getHost());
       socket.emit('connection', {
           console.log('*******');
       });
   
       socket.on('disconnect', function() {
           console.log('*******');
       });

Solution

  • Just to clarify the issue, the problem was resolved by configuring the proxy in the httpd.conf file with the WebSocket protocol using the following settings:

    ProxyPass /socket.io ws://127.0.0.1:5001/socket.io connectiontimeout=3000 timeout=3000
    ProxyPassReverse /socket.io ws://127.0.0.1:5001/socket.io
    

    This allowed for successful communication between the server and the application.I hope this solution helps somebody else facing a similar issue in the future!