mmm, I made this a while ago, I put some network read function in a separated thread (so the gui doesn't freeze when there is some connection problem) and validated the socket connection if is valid before using it. Here the patch with the battery fix and here the whole patch.