First, start by confirming that it is not any side of the application closing the connection after some idle time period. This can be done by capturing traffic (in Windows use Wireshark and tcpdump in Linux) in both sides and then inspect it looking for closure related packets (e.g. FIN or RST).
Now, if you confirm that none of the application sides is closing the connection, but when you try to send a new packet after a given timeout the connection is not valid anymore (you will observe several retransmission attempts in the traffic log), chances are that this is caused by a stateful firewall removing connections from its state table after a given idle session timeout, for example, the Linux Netfilter idle connection tracking timeout defaults to 5 days as indicated in https://www.kernel.org/doc/Documentation/networking/nf_conntrack-sysctl.txt, nf_conntrack_tcp_timeout_established.
Now for troubleshooting the previous condition, start by shortening the network path between the client and the server (e.g. by using a VPN to put the client and the server in the same subnet) and check that the connection doesn't timeout anymore, just to be sure.
Then, from the regular network path (or incrementally adding nodes to it), open a new connection, wait for X time and try to send a new packet, if it arrives, then double the X value and send the packet again and keep doing this until the packet is not sent anymore, which would provide you a good idea of the configured timeout. Now, of course the previous could be automated with a simple multithreaded client application, otherwise it is just a horrible testing experience.