Fixed handling of messages larger than 1024 bytes
Fixes https://github.com/parnic/node-screenlogic/issues/5
This commit is contained in:
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
### Fixed
|
||||||
|
* Messages larger than 1024 bytes are now handled properly.
|
||||||
|
|
||||||
## v1.2.0 - 2019-02-22
|
## v1.2.0 - 2019-02-22
|
||||||
### Added
|
### Added
|
||||||
* Remote connection through Pentair servers
|
* Remote connection through Pentair servers
|
||||||
|
16
index.js
16
index.js
@ -124,8 +124,22 @@ class UnitConnection extends EventEmitter {
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
this.client = new net.Socket();
|
this.client = new net.Socket();
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
var buffer = Buffer.alloc(1024);
|
||||||
|
var bufferIdx = 0;
|
||||||
|
|
||||||
this.client.on('data', function(msg) {
|
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) {
|
}).on('close', function(had_error) {
|
||||||
// console.log('unit connection closed');
|
// console.log('unit connection closed');
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user