You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
728 B
32 lines
728 B
const fs = require('fs');
|
|
const ipc=require('../../../node-ipc');
|
|
const cpuCount = require('os').cpus().length;
|
|
const cluster = require('cluster');
|
|
const socketPath = '/tmp/ipc.sock';
|
|
|
|
ipc.config.unlink = false;
|
|
|
|
if (cluster.isMaster) {
|
|
if (fs.existsSync(socketPath)) {
|
|
fs.unlinkSync(socketPath);
|
|
}
|
|
|
|
for (let i = 0; i < cpuCount; i++) {
|
|
cluster.fork();
|
|
}
|
|
}else{
|
|
ipc.serve(
|
|
socketPath,
|
|
function() {
|
|
ipc.server.on(
|
|
'currentDate',
|
|
function(data,socket) {
|
|
console.log(`pid ${process.pid} got: `, data);
|
|
}
|
|
);
|
|
}
|
|
);
|
|
|
|
ipc.server.start();
|
|
console.log(`pid ${process.pid} listening on ${socketPath}`);
|
|
}
|
|
|