-
I am running socket.io with cluster module, emits to specific client are working, but broadcasts are unreliable, sometimes not everyone in room recieves message. I did use socket.io-redis to store rooms across clusters but that didn't work. const cluster = require("cluster");
const express = require("express");
const app = express();
const { Server } = require("socket.io");
const redisAdapter = require("socket.io-redis");
const numCPUs = require("os").cpus().length;
const {setupMaster, setupWorker} = require("@socket.io/sticky");
if (cluster.isMaster) {
const socketServer = app.listen(3001);
setupMaster(socketServer, {
loadBalancingMethod: "least-connection",
});
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
};
cluster.on("exit", function () {
cluster.fork();
});
} else {
const server = app.listen(3000);
const io = new Server(server, {
cors: {
origin: ["http://localhost:3000"]
}
});
io.adapter(redisAdapter({ host: "localhost", port: 6379 }));
setupWorker(io);
io.on("connection", function (socket) {
// I send broadcasts here...
});
}; |
Beta Was this translation helpful? Give feedback.
Answered by
crupeng-1
Jun 14, 2021
Replies: 1 comment
-
Turns out I was broadcasting incorrectly. Nevermind |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
crupeng-1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out I was broadcasting incorrectly. Nevermind