[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Preemptive socket connection monitoring
Maybe create a non-block read() class. Then it can fail out on socket
On Thu, 2002-11-21 at 17:17, Gary Herndon wrote:
> I am currently trying to come up with a good way to check the connection
> behind a socket to make sure it hasn't been dropped. I would like to do
> this without reading/writing the streams and catching the exception. My
> current method of thinking was use the PushBackInputStream as a wrapper for
> the Socket.getInputStream() and then attempt to read/unread 1 byte anytime I
> wanted to know if the socket was up. If the socket was down, the read would
> fail and I could return a FAIL, otherwise, I would just push the byte back
> on the stream, and return a SUCCESS. (I haven't looked too much at Readers
> since my data is not a character stream).
> I have 2 questions.
> 1: Is this a good way to handle the problem?
> 2: The problem I see with this method is that the isConnected() method I
> write would block if there was no data on the InputStream... can this be
> I imagine that all my problems would be solved with the java.nio of 1.4, but
> currently I have to work on a 1.3 JVM, so please keep that in mind when
> offering suggestions.
> Gary Herndon