worker.js
const io = require('socket.io')(3000);
const clusterAdapter = require('socket.io-adapter-cluster');
io.adapter(clusterAdapter());
master.js
const cluster = require('cluster');
const clusterAdapter = require('socket.io-adapter-cluster/master');
cluster.setupMaster({
exec: 'worker.js',
});
cluster.fork();
clusterAdapter();
The following opts
are allowed:
key
: the name of broadcast prefix, default(socket.io
)client
: the client of broadcast
The socket.io-adapter-cluster
adapter broadcast with prefix:
prefix#namespace#
If broadcasting to a single room:
prefix#namespace#room#
The socket.io-adapter-cluster
is a simple and cluster-version of socket.io-redis
.
MPL-2.0