mathiask88 / node-snap7

node.js wrapper for snap7
MIT License
163 stars 59 forks source link

s7client connectTo() takes a very long time to return an error callback #54

Closed Jay031 closed 4 years ago

Jay031 commented 5 years ago

Hi guys,

I have a simple piece of code which works on Windows but not on MacOS.

s7client.ConnectTo(uri, 0, 0, function (err) {
    if (err) {
      let errorText = s7client.ErrorText(err)
      console.error(`Connection failed! ${errorText}`);
      socket.emit("info", `Connection failed! ${errorText}`);
    } else {
      console.info("Connection established!");
      setupPLCRead(s7client);
    }
  });

When there is an error, i.e. "TCP connection failed" it returns immediately on Windows and logs the 'connection failed'.

On mac it takes more than 30 seconds to return the error callback. I've tested this when being in the wrong network and trying to connect. Then, when I switch to the right network, it immediately logs the 'Connection established'.

This behaviour only occurs on MacOS. Does anyone know how I can fix this problem? I've already tried setting all s7client Timeout params to 2000 like this: s7client.SetParam(s7client.SendTimeout, 2000);

thanks in advance!

mathiask88 commented 5 years ago

UNIX and Windows socket behavior can be very different. You should check your OS TCP settings like sysctl -n net.inet.tcp.keepinit It is also a difference if it is a new connection or if there was already a connection established.