任何人都知道如何在Windows上运行Node Cluster?我还没能在网上找到任何文章,似乎无法解决这个问题:
events.js:160
throw er; // Unhandled 'error' event
^
Error: write ENOTSUP
at exports._errnoException (util.js:1007:11)
at ChildProcess.target._send (internal/child_process.js:634:20)
at ChildProcess.target.send (internal/child_process.js:521:19)
at sendHelper (cluster.js:751:15)
at send (cluster.js:534:12)
at cluster.js:509:7
at SharedHandle.add (cluster.js:99:3)
at queryServer (cluster.js:501:12)
at Worker.onmessage (cluster.js:449:7)
at ChildProcess.<anonymous> (cluster.js:765:8)
代码......
if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('online', (worker) => {
console.log('Worker ' + worker.process.pid + ' is online');
});
cluster.on('exit', (worker, code, signal) => {
console.log(`Worker ${worker.process.pid} died with code ${code} and signal ${signal}`);
});
} else {
console.log('else part ');
openPort();
}
function openPort() {
let server = dgram.createSocket('udp4');
server.bind(port, host);
server.on('message', processMessage);
}
答案 0 :(得分:1)
v0.11.14(适用于Linux和OSX)中添加了对UDP群集的支持。 检查node.js master上的file,其中说明&#34;目前Windows不支持dgram集群&#34;
答案 1 :(得分:1)
在当前节点的js版本中,我使用下面的代码在Windows上创建集群。
<div style="width:100%;" id="comboDiv">
<div style="width: 100px; display: inline-block">
<select style="width: 100%;"></select>
</div>
<div style="width: 200px; display: inline-block">
<select style="width: 100%;"></select>
</div>
<input type="text" style="width: 10%; float:right;" />
</div>
这将在同一端口上创建集群。
答案 2 :(得分:0)
因此,为了在Windows上使用带有Node群集的UDP,你必须像这样调用server.bind:
server.bind({port: 1900, exclusive: true}, function () {
console.log('PORT BIND SUCCESS');
server.setBroadcast(true);
server.setMulticastTTL(128);
server.addMembership(multicastAddress, myIp);
});
关键部分是将对象{port:PORT,exclusive:true}传递给bind函数。我在这里找到了答案:https://github.com/misterdjules/node/commit/1a87a95d3d7ccc67fd74145c6f6714186e56f571