You can try TCP keepalives.
7200
75
9`
In the above example, the TCP continue timer starts after 7200 seconds of inactivity. If keep-alive messages are unsuccessful, they are repeated at intervals of 75 seconds. After 9 consecutive attempts to reconnect, the connection will be disconnected.
keepalive , script /etc/init.d.