Lost of comm in TCP

Hellow, I am developing a software fot to read modbus TCP and register data into a txt file. The problem I have seen, is in a lost of comunication in the tcp, the reading values, is locking, not shows 0. In the text box, appears the last frozen value. How can I to know when is a lost of comm?