caobo171 / node-zklib

This is a lightweight of node.js module to connect to biometrix attendance device for examples ZKTeco
72 stars 61 forks source link

ZKError: TIMEOUT_ON_WRITING_MESSAGE upon client socket reconnect. #27

Open edwin1028 opened 4 years ago

edwin1028 commented 4 years ago

Good day! I'm attempting to connect multiple devices and use socket.io to emit data to client side. At first load of the server everything works fine, It say's "ok tcp" and "ok udp" but after/upon reloading the client app im having a problem with the udp type device. Here is the error:

 ZKError {
      err: Error: TIMEOUT_ON_WRITING_MESSAGE
      at Timeout.<anonymous> (C:\workspace\zktime-logs\backend\node_modules\node-zklib\zklibudp.js:101:20)
      at listOnTimeout (internal/timers.js:531:17)
      at processTimers (internal/timers.js:475:7),
      ip: 'XXX.XXX.XX.XX',
      command: '[UDP] undefined'
 }

Here is my code below:

constructor(server) {
    this.io = sio.listen(server);
    this.io
      .on("connection", (socket) => {
        devices.forEach(async (device, index) => {
          const zkInstance = new ZKLib(device.ip, 4370, 10000, 4000);
          try {
            await zkInstance.createSocket();
            console.log(await zkInstance.getInfo());

            await zkInstance.getRealTimeLogs((data) => {
              console.log(data);
            });
          } catch (e) {
            console.log(e);
            if (e.code === 'EADDRINUSE') {
            }
          }
        });
      });
  }

Thank you in advance for the help!

Benitez25 commented 3 years ago

Hello, did you solve the problem?. That happens to me too

zhfahan77 commented 3 years ago

any update facing same problem here,

image

fernandomonterroso commented 3 years ago

Tengo el mismo problema.

jmikepaz commented 2 years ago

same problem when try zkInstance.getTime()

jmikepaz commented 2 years ago

same problem when try zkInstance.getTime() new ZKLib(address, port, timeout , inport); I resolve error timeout = 10000;

merouanezouaid commented 2 years ago

any update facing same problem here,

image

I fixed it you just need to remove await in the timeout method and it works perfectly fine for me

The code is in zklibtcp.js file:

writeMessage(msg, connect) {
    return new Promise((resolve, reject) => {

      let timer = null
      this.socket.once('data', (data) => {
        timer && clearTimeout(timer)
        resolve(data)
      })

      this.socket.write(msg, null, async (err) => {
        if (err) {
          reject(err)
        } else if (this.timeout) {
          timer = setTimeout(() => {
            clearTimeout(timer);
            reject(new Error('TIMEOUT_ON_WRITING_MESSAGE'));
          }, connect ? 2000 : this.timeout)
        }
      })
    })
  }

I updated some functionalities and resolved most of the issues in my module based on this package Feel free to check it out: https://github.com/merouanezouaid/zklib-js

marwanzak commented 1 year ago

had anyone solve it yet? I have the same issue with some devices and not all of them

beatrx30 commented 8 months ago

My case is my ZKteco G2 was offline so i can't make a TCP connect to it, even though i can ping to the device 's IP. So make sure your device is online and be abled to connect. And If other computer is connecting to the attendence device, you still can connect to it by TCP, i dont use UDP so i don't know if it worked.