To test for a connection failure, you will need to check the number of messages: -1 indicates a connection error.