Try using the BIO functions to see if it helps against disconnections