Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing to spot message end #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/client/tcp-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@ TcpClient.prototype.connect = function(callback) {
self.client = net.connect({host: self.host, port: self.port}, function() {
self.client.on('data', function(data) {
self.responseBuffer += data.toString();
if (self.responseBuffer.substring(self.responseBuffer.length - 2, self.responseBuffer.length) == FS + CR) {

/*
'Sometimes' the responseBuffer contains things like FS or CR, and so
self.responseBuffer.substring() stops copying early, and the compare to FS+CR fails
So try a real parse, see if it's a response.
*/
var _parsed = false;
var _ackish = false;
try{
const ackish = self.parser.parse(self.responseBuffer.substring(1, self.responseBuffer.length - 1));
_parsed = true;
}catch(e){
console.log('ackish',e)
}

if (self.responseBuffer.substring(self.responseBuffer.length - 2, self.responseBuffer.length) == FS + CR || _parsed) {
var ack = self.parser.parse(self.responseBuffer.substring(1, self.responseBuffer.length - 2));
self.callback(null, ack);
self.responseBuffer = "";
Expand Down