Good evening, i'm struggling with a socket connection. I use socket.io in the nodejs-express backend and ngx-socket-io in the angular frontend, but at the connection i continuosly receive 400 stat ({"code":2,"message":"Bad handshake method"}) alternate with 200 stat width sid: 0{"sid":"REeYoGC5t_JnTp4dAABp","upgrades":"websocket"],"pingInterval":25000,"pingTimeout":5000}).
[Here there is a screenshot of chrome's net tab][1]
Here it is the server
const app = express();
const server = http.createServer(app);
server.listen(PORT, () => {
console.log("Server is listening on " + PORT, colors.yellow);
init();
});
const io = require("socket.io")(server, {
cors: {
origin: ["http://localhost:4200", "https://myurl.com",],
credentials: true
}
});
io.on("connection", (socket) => {
console.log("Connected");
socket.emit("ok","ok");
socket.on("disconnect", (data) => {
});
});
And here there is the client
const config: SocketIoConfig = {
url: environment.SERVER_ENDPOINT,
options: { autoConnect: false, withCredentials: true}
};
...
imports: [
SocketIoModule.forRoot(config)
]
...
Can someone help me with this? [1]: https://i.sstatic.net/72YSB.png
EDIT I've resolved this using socket.io-client instead of ngx-socket-io
Try to downgrade version , it was fine with socket.io 2.3.1