Привязать к тому же сокету UDP в кластере NodeJS в Windows?
Я пытаюсь запустить кластерное UDP-приложение NodeJS, работающее в многоплатформенном режиме. Вот код, который прекрасно работает в системе Enterprise Linux:
const cluster = require('cluster');
const dgram = require('dgram');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster)
{
console.log('Initializing...');
// Fork workers.
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
}
else
{
const server = dgram.createSocket({
type: 'udp4'
});
server.on('listening', () => {
const address = server.address();
console.log(`Worker ${process.pid} is listening on ${address.address}:${address.port}`);
});
server.on('message', (msg, rinfo) => {
console.log(`${msg} received on process ${process.pid}`);
});
server.bind({
port: 41234
});
}
Вывод как ожидалось:
Initializing...
Worker 11811 is listening on 0.0.0.0:41234
Worker 11817 is listening on 0.0.0.0:41234
Worker 11823 is listening on 0.0.0.0:41234
Worker 11829 is listening on 0.0.0.0:41234
Some bytes received on process 11829
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11817
Some bytes received on process 11823
Some bytes received on process 11823
Some bytes received on process 11823
Some bytes received on process 11823
Some bytes received on process 11823
Тем не менее, тот же код выше не работает в Windows, выбрасывая ошибку "write ENOTSUP". Я думал, что это исправит, это добавление
reuseAddr: true
к вариантам по созданию розетки, но без сигары. В сочетании с эксклюзивной опцией bind создается впечатление, что все работники работают на одном и том же порту, но все запросы, похоже, отправляются первому созданному работнику, а не распространяются. Буду признателен за любую помощь, так как я не хочу идти по пути управления работниками на нескольких портах через nginx или какой-либо другой шаблон!