Is there a better way to do this? If not, is there an effective way to check if you have a package? Or is something already there that allows you to check if the other end is alive?
If the problem is with the connection, the TCP stack will tell you very quickly when you send your own keep alive packet. It contains a method to verify that packets were received and in the correct order.
Now, if you want to receive an explicit confirmation that your package has been received, you must send the other end of the confirmation. This is excessive IMHO, but this is what you would need to do.
If you do not receive a response within a reasonable delay (10 seconds is more than enough), and if the TCP stack did not cause any error, this means that the listening side / application on the other side is not doing work. The problem is at the application level, not the TCP stack level.
source share