First Commit of new way of building the Platform
This commit is contained in:
1 parent
e48cf0dae5
commit
40e60b42cc
4616 files changed
+713402
No files matched your search
+31
@@ -0,0 +1,31 @@
|
||||
const fs = require('fs');
|
||||
const ipc = require('../../node-ipc');
|
||||
|
||||
const socketPath = '/tmp/ipc.sock';
|
||||
|
||||
//loop forever so you can see the pid of the cluster sever change in the logs
|
||||
setInterval(
|
||||
function() {
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
socketPath,
|
||||
connecting
|
||||
);
|
||||
},
|
||||
2000
|
||||
);
|
||||
|
||||
function connecting(socket) {
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function() {
|
||||
ipc.of.world.emit(
|
||||
'currentDate',
|
||||
{
|
||||
message: new Date().toISOString()
|
||||
}
|
||||
);
|
||||
ipc.disconnect('world');
|
||||
}
|
||||
);
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
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}`);
|
||||
}
|
||||
Reference in new issue
Block a user