I'm trying to read items from a socket and I notice that if there is nothing on the stream of the socket it will stay at the read and back up my application. I wanted to know if there was a way to set a read timeout or terminate the connection after a certain amount of time of nothing in the socket.
A:
Yes, there should be an override of Read() that accepts a timeout value.
Kelly French
2010-08-25 22:38:26
And you don't read directly from a socket anyway, you get an `InputStream` from the socket and then read from that. Do what @erikson says, use `setSoTimeout()`.
krock
2010-08-25 22:49:15
@Kelly - no there shouldn't. That would make the `SocketInputStream` API different from other streams. There is already a way to do this that doesn't break the `InputStream` substitutability.
Stephen C
2010-08-26 00:44:08
+2
A:
If you write Java, learning to navigate the API documentation is helpful. In the case of a socket read, you can set the timeout option.
erickson
2010-08-25 22:39:30