J
J
jtag2018-05-17 06:14:27
Node.js
jtag, 2018-05-17 06:14:27

How can you find out from which request the response came to the net modules?

Understanding the net module. I wrote two sending a request to the device and a response event handler. How can you find out from which request the response came from? At the moment, the response handler simply checks the key bits and finds out which request the response came from. Can I somehow attach an event handler to the request?

const net = require('net')
let config = new net.Socket()
config.connect(18902, '192.168.0.40', function() {
  console.log('Connected to config port')
});
config.write(getCmdConnect(idses, key, sd), 'ascii')   //запрос начала сессии

config.write(getCmdReadConfig(idses, SOFTWARE_VERSION), 'ascii')   //запрос версии прошивки

config.on('data', function(data) {
  if(data[4]==FAC_DIAGNOSTIC & data[5]==DGN_READ_CONFIG & data[18]==SOFTWARE_VERSION) {
    console.log("Received software version")
  }
        if (data[4] = FAC_SESSION .......
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question