0

(Note - this is not a duplicate - the question explicitly mentions not modifying the InputStream.)

I want to be able to check if the remote end of the connection is closed without modifying the socket's InputStream. I can't call read() on the InputStream because that will read data, and other portions of the code are going to be reading from the socket and expecting that data.

I've also tried calling read() with a 0-length buffer, but that doesn't work either (returns 0 instead of -1, even if the connection is broken).

(I guess what I want to do is call read() and if the result is not -1, "push" the byte back into the InputStream.)

Is there any way to get around this?

Thanks!

osman
  • 1,590
  • 1
  • 14
  • 21

1 Answers1

-1

You can use the function isReachable() to do that.
Here is an example : http://kodejava.org/how-do-i-ping-a-host/

tonystrawberry
  • 102
  • 1
  • 2
  • 12
  • Nope, I know for sure that the remote end is reachable, I just want to check if the connection still exists without modifying the socket's InputStream. – osman Jun 13 '14 at 21:59
  • isReachable() does not check if a connection is closed. -1 – user207421 Jun 15 '14 at 00:24