For others who might be having this problem, I have found a
workaround, I am performing an outputbuffer write and catching the
IOexception when the server side connection is gone, however, I would
still like to know if I could do the same with a read.
Thanks
Ryan
smoothop - 16 Jun 2007 22:01 GMT
On Jun 16, 5:36 pm, RFlem...@NationalSteel.com wrote:
> For others who might be having this problem, I have found a
> workaround, I am performing an outputbuffer write and catching the
[quoted text clipped - 4 lines]
>
> Ryan
ServerSocket server = new ServerSocket(port);
// timeout after 60 seconds
server.setSoTimeout(60000);
try {
Socket socket=server.accept();
}
catch ( java.io.InterruptedIOException e ) {
System.err.println( "Timed Out (60 sec)!" );
}
This is true for READ operation too. Since READ operation blocks as
long necessary it may be wise to use the setSoTimeout() method. Note
that when the TIMEOUT expires, an InterruptException is thrown.
However, the socket is still connected even though the Exception was
raised.
quote from http://www.rgagnon.com/javadetails/java-0086.html Maybe you
also make a try with timeOut parameters.
> From reading documentation, I would expect a 0 return value for a proper connection
> with no data, a -1 return value or IOexception for a bad socket
> connection.
Nope. You will only get the zero in non-blocking mode, and you will
never get -1 for a bad socket connection, only for one that has been
cleanly closed by the other end, and you're not very likely to get an
IOExeption either. You mostly get those when *writing*.
However, what is happening is that the socket connection
> is still open on both sides, the read times out and generates an
> IOexception error described as Read timed out.
That's correct behaviour if you set a timeout, which also implies that
you are in blocking mode. Usually NIO is used in non-blocking mode in
conjunction with Selector.select().
> Does the JAVA examples only work when the server is also a NIO object?
No, it neither knows nor cares.
RFleming@NationalSteel.com - 17 Jun 2007 12:07 GMT
Thanks for the reply. As you stated below, apparently I am still
using blocking mode. I thought that by checking the inputstrea
available method that I was doing the Java equivalent to non
blocking. Apparently I still have more learning to do (like it ever
stops)!
On Jun 17, 4:17 am, Esmond Pitt <esmond.p...@nospam.bigpond.com>
wrote:
> That's correct behaviour if you set a timeout, which also implies that
> you are in blocking mode. Usually NIO is used in non-blocking mode in
> conjunction with Selector.select().