it is normal that server closes an unused tcp connection. I didn't find in Arduino networking API a keep-alive setting for the socket. I simple reconnect if the connection to server is not connected.
if (!client.connected()) {
client.stop();
client.connect(serverAdress, 502);
if (!client.connected()) {
client.stop();
return CONNECT_ERROR;
}
}