Fixed handling of messages larger than 1024 bytes
Fixes https://github.com/parnic/node-screenlogic/issues/5
This commit is contained in:
16
index.js
16
index.js
@ -124,8 +124,22 @@ class UnitConnection extends EventEmitter {
|
||||
this.password = password;
|
||||
this.client = new net.Socket();
|
||||
var _this = this;
|
||||
var buffer = Buffer.alloc(1024);
|
||||
var bufferIdx = 0;
|
||||
|
||||
this.client.on('data', function(msg) {
|
||||
_this.onClientMessage(msg);
|
||||
if (buffer.length < msg.length + bufferIdx) {
|
||||
buffer = Buffer.alloc(msg.length + buffer.length, buffer);
|
||||
}
|
||||
|
||||
msg.copy(buffer, bufferIdx);
|
||||
bufferIdx = bufferIdx + msg.length;
|
||||
|
||||
var expectedLen = msg.readInt32LE(4) + 8;
|
||||
if (msg.length === expectedLen) {
|
||||
_this.onClientMessage(buffer);
|
||||
bufferIdx = 0;
|
||||
}
|
||||
}).on('close', function(had_error) {
|
||||
// console.log('unit connection closed');
|
||||
});
|
||||
|
Reference in New Issue
Block a user