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

Patch to read and write to return the sid #12

Open
gabrieleturchi opened this issue Mar 1, 2018 · 3 comments
Open

Patch to read and write to return the sid #12

gabrieleturchi opened this issue Mar 1, 2018 · 3 comments

Comments

@gabrieleturchi
Copy link

To be able to track multiple parallel requests, I simply added:
return self.header.SID;
to FinsClient.prototype.read and FinsClient.prototype.write.

It is possible to have this patch in the code?

Thank you.
GT

@iceoneye
Copy link

iceoneye commented Mar 14, 2018

client.read('D00000', 5, function (err, bytes) {
console.log("Bytes: ", bytes);
console.log("SID: ", client.header.SID);
});
Please try this.

@gabrieleturchi
Copy link
Author

Mhhh..... This way I can see two different problems: I need to use a callback that otherwise I don't need, and because I'm using a single client to run multiple different read & write, and I need the SID to be able to identify the correct answer, so the "client" object in the meantime could have changed.

@CharlieMarshall
Copy link
Contributor

CharlieMarshall commented Jun 22, 2020

The way I handle SIDs without the need for callbacks or for adding a return is in the client.on('reply'). Here I am expecting 17 SIDs and on getting them all we close the connection. They often do not arrive in order therefore we need an if / else or switch statement.

client.on('reply',function(msg) {
  if(msg.sid==1) {
    // code to handle SID 1
  }
  else if(msg.sid==2) {
    // code to handle SID 2
  }
  else if(msg.sid==3) { 
    // code to handle SID 3
  }
  // etc
else if(msg.sid > 17){
    console.log("ERROR invalid SID: " + msg.sid);
    client.close();
    console.log("Return 10");
    return process.exit(10);
  }

  if(++replyCounter==17){
    client.close();
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants