@nus I don't think I have the energy to dig into what it's doing, but on a high level, I'd make it use a background activity that maintains a TCP socket to the server and blocks waiting for input from it. With keepalive set in the socket options so kernel avoids droppage by bad NATs. No execution of any code except when data is received or connection drops & needs to be reestablished.