0

In my current project I use socket.io-redis to scale my socket.io servers. However, when trying to connect to the reds server, I get the following error :

Error during WebSocket handshake: Unexpected response code: 400

My client side code :

const socket = io(<url to redis server>, {transports: ['websocket']})

My server side code:

const redis = require('socket.io-redis');

io.adapter(redis({ host: 'localhost', port: 6379 }));
  • follow these answers https://stackoverflow.com/questions/41381444/websocket-connection-failed-error-during-websocket-handshake-unexpected-respon/41383819#41383819 – Heartbit Nov 03 '20 at 18:21
  • 1
    @SaeidAlidadi The error is still there. Is it because I am using the redis url ? – cdermasterxie Nov 03 '20 at 18:30
  • You should connect your socket client to your server. the `.io.redis` is just an adapter for multiple instances of one `nodejs` server for sharing socket sessions between them. – Heartbit Nov 03 '20 at 18:38
  • 1
    @SaeidAlidadi So I have to connect it to my biggest server and not to redis – cdermasterxie Nov 03 '20 at 18:41
  • @SaeidAlidadi I thought that redis manages incoming connections and splits it up between servers – cdermasterxie Nov 03 '20 at 18:43
  • You should just connect all of your servers that have the same logic to one redis with the adapter and then connect socket clients to these servers. the connection has a round robin behavior so one client will connected to one server and this will retried if your connection get lost – Heartbit Nov 03 '20 at 18:56

0 Answers0