问题描述
我有以下代码,因为有N个套接字发送顺序流。 如何使用nodejs中的工作线程进行扩展。
const Net = require('net');
const port = 8080;
const server = new Net.Server();
const processor = require('processor.js');
server.listen(port,function() {
console.log(`Server listening for connection requests on socket localhost:${port}`.);
});
server.on('connection',function(socket) {
console.log('A new connection has been established.');
let connectionInfo = {};
connectionInfo.id = `${socket.remoteAddress}:${socket.remotePort}`;
connectionInfo.partialBuffer= undefined;
socket.on('data',function(chunk) {
let chunkBuffer = Buffer.from(chunk);
if(connectionInfo.partialBuffer){
chunkBuffer = Buffer.concat([connInfo.partialBuffer,chunkBuffer]);
}
processor.processChunk(connectionInfo,chunkBuffer); // set connectionInfo.partialBuffer in processChunk() function
});
socket.on('end',function() {
console.log('Closing connection with the client');
});
socket.on('error',function(err) {
console.log(`Error: ${err}`);
});
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)