node-zklib icon indicating copy to clipboard operation
node-zklib copied to clipboard

ZKError: TIMEOUT_ON_WRITING_MESSAGE upon client socket reconnect.

Open edwin1028 opened this issue 5 years ago • 8 comments

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!

edwin1028 avatar Oct 01 '20 05:10 edwin1028

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

Benitez25 avatar Oct 19 '20 17:10 Benitez25

any update facing same problem here,

image

zhfahan77 avatar Feb 15 '21 07:02 zhfahan77

Tengo el mismo problema.

fernandomonterroso avatar Apr 27 '21 17:04 fernandomonterroso

same problem when try zkInstance.getTime()

jmikepaz avatar Feb 21 '22 20:02 jmikepaz

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

jmikepaz avatar Feb 21 '22 21:02 jmikepaz

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

merouanezouaid avatar Mar 02 '22 10:03 merouanezouaid

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

marwanzak avatar Nov 03 '22 20:11 marwanzak

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.

beatrx30 avatar Jan 16 '24 08:01 beatrx30