Broken Pipe after wago is idle

Hello !
I connect to a wago device using modbus TCP connection. When I try to perform write operation after this connection is idle (no read/write) for certain period of time, I get the “Broken Pipe” error.

As I am using wago for the first time, I don’t know how I should configure it to maintain a healthy connection, even after the connection is idle for some time.

PLC model ? Firmware version? Development environment?

you probably got the socket closed because of the timeout.
you should use the TCP keepalive system to keep the socket open.

I just had one doubt, does the KeepAlive probe resets TCP connection timer?
Suppose, Keepalive probes are being sent every 5 minutes.
The TCP timeout is 20 minutes.
Suppose I did a write at 10:00 and then the connection was idle for 20 minutes.
So, Keepalive probe was sent 4 times.
So, if no read or write was performed between 10:00 to 10:20, would the connection be considered idle and break due to TCP timeout, or would it consider Keepalive probes as some activity?

keepalive are made to reset the TCP timeout. as the name say it keep alive the TCP connection.