Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

JAVA NIO

Thread view: 
RFleming@NationalSteel.com - 16 Jun 2007 14:57 GMT
Hello,

Somewhat new to JAVA, and I swear I have looked all over on this
problem, and found an answer, but it does not seem to work.  I have a
non blocking NIO socket client connection I can send data to the
socket check the input buffer for data and handle it okay.  If no
activity occurs in say 10 seconds, I do an input read.  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.  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.  Does the JAVA examples
only work when the server is also a NIO object?  I say this because
the server I am using is not written in JAVA.  Any help or suggestions
would be greatly appreciated!

Thanks

Ryan
RFleming@NationalSteel.com - 16 Jun 2007 15:36 GMT
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.
Esmond Pitt - 17 Jun 2007 09:17 GMT
> 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().


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.