Talkredius
while debugging the memory leak a general question came up for me :

are there any general rules in the standard how to handle a TCP connection ?

E.g :

If I open a TCP connection to a slave to poll data do I have to close the connection explicitly after polling ?
Are there any build in timeouts to close a connection or has this to be done by master and/or slave ?
If so we should consider to integrate timeouts in the server.cpp file in the case client or master crashes
Reply 0 0
thiagoralves
I don't think the Modbus standard says anything about it. I've seen HMI software that opens a new connection every time its polling data, and also HMI software that keeps the TCP connection alive. About the timeout thing, since TCP is connection oriented, I believe it's already implemented in the lower layer. If the client crashes, the TCP channel will be closed eventually.
Reply 0 0
Talkredius
Now I did run into a TCP problem and I can explain it better :

App1 is running 24/7 on a shuttle PC (opensuse 42.2) and crashes every 7 days or so due to an apache2/distro bug on the shuttle PC, can't debug it right now. After every crash a restart of the shuttle is necessary.
openplc is running on a raspi, max number of TCP connections is 5 (hardcoded into openplc)

App1 opens a TCP connection and polls data for ever. On the openplc side the serving process is detached after opening the TCP connection and waits for data polls for ever, even if openplc is killed it still waits there for data. When app1 is restarted a new TCP connection is used, the old detached process is still waiting but not used anymore. This goes well until the 6th restart, when no new TCP connection is available

So I think it would be a good idea to define a (configurable?) timeout, after which the detached process closes the tcp connection and finish itself if no data transfer has happened since start of the timeout
Reply 0 0
thiagoralves
Got it. I'll check if there is a way to setup a timeout for the TCP connection.
Reply 0 0
Reply