[英]Is there any way to use parentPort.on() in worker threads in node js with server.listen()
每當我嘗試使用具有
工人檔案 =>
parentPort.on('message',msg =>{
//some code here
})
主文件 =>
server.listen(3000,function(){
console.log('Server running');
});
服務器已經在監聽它給出了這個錯誤
Error: listen EADDRINUSE: address already in use 127.0.0.1:3000
at Server.setupListenHandle [as _listen2] (net.js:1314:16)
at listenInCluster (net.js:1362:12)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1499:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:68:8)
Emitted 'error' event on Worker instance at:
at Worker.[kOnErrorMessage] (internal/worker.js:233:10)
at Worker.[kOnMessage] (internal/worker.js:243:37)
at MessagePort.<anonymous> (internal/worker.js:164:57)
at MessagePort.emit (events.js:315:20)
at MessagePort.onmessage (internal/worker/io.js:78:8)
at MessagePort.exports.emitMessage (internal/per_context/messageport.js:11:10) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '127.0.0.1',
port: 3000
}
我試過使用 MessageChannel() 但它也給出了同樣的錯誤。 請您告訴錯誤的原因是什么以及如何糾正它。
EADDERINUSE 聽起來您正在嘗試在主文件和工作線程中的同一端口上啟動新服務器。
您需要確保您沒有嘗試在工作線程中啟動服務器,或者如果您想要工作線程中的服務器,那么它們每個都必須位於唯一的端口上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.