I have an application handling several Java socket connections to different kinds of remote machines (some PCs, others are embedded devices). These sockets and streams should not close indefinitely except for a very good reason (e.g. crash of remote system).
I frequently encounter an issue where the input stream ends unexpectedly, without any reason (value is -1), i.e. the remote machine does not signal a connection abort. But when I discard these -1 reads and continue reading from the stream, the remote machine actually sends new data later. This can go on for a very long time. I also can still write to the output stream too.
In the current situation, I have the choice between treating -1 as end of stream and close the socket (with false positives), or ignore -1 input and risk not being notified of real disconnects.
I haven't been able to create a working example of this issue and the problems appear randomly.
Any ideas what's wrong?
Edited to add: The Java endpoint is a rewrite of an existing VB application that did not have these problems (at least to my knowledge).