A way is to periodically ping your server. If no response arrives in a certain period, you'll get a strems_error.
You can also have a look at how b4a bridge works (its source code). You'll find a disconnect timer, which after 10 ticks closes the connection (meaning no activity was found, which would reset the timer, as far as I understood).