my dog learned polymorphism*
The moose likes I/O and Streams and the fly likes Java.io Read blocking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Java.io Read blocking " Watch "Java.io Read blocking " New topic
Author

Java.io Read blocking

terry Kiernan
Ranch Hand

Joined: Aug 23, 2008
Posts: 31
Hi ,
I am experiencing a problem with blocking on read using the the following stream.

I don't want to use available() as this is conlicting with the ssl client

Can some one suggest how I can solve this where by the read won't block .

Any suggestions much appreciated .

private TelnetClient client;
private BufferedInputStream is;
is = new BufferedInputStream(client.getInputStream());
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

[I assume you are using Apache commons TelnetClient]

You can only have a non blocking read if the stream you get can give you a SelectableChannel which the class you are using does not seem to provide.
That was a point to point answer to your question
However, if you tell us more about your problem i.e. why is it that you do not want to block the read or in which situation you do not want to block a read. We will be able to give you some alternatives, if possible.


apigee, a better way to API!
terry Kiernan
Ranch Hand

Joined: Aug 23, 2008
Posts: 31
Yes, I am using the org.apache.commons.net.telnet.TelnetClient however i need to use BufferedInputStream from java.io

Why i can't use the available() is because when I try to do a connection over ssl it falls over.

I want the option to use a telnet hand shake or a ssl hand shake

but when I call the available() method as i read back from the stream when using the ssl handshake (SSLSocket) it won't connect however when I use the telnet all is fine and of course the read doesn't BLOCK.

Thats why i can't use the available method as it breaks the SSLSocket connection. so was hoping if i could use read that won't block or some other way to get around this issue....

I switched on debug on the SSL connection
System.setProperty( "javax.net.debug", "ssl");

and i got this in my output when i was calling the java.io.available() method
EOF received that violates SSL protocol

[ December 11, 2008: Message edited by: terry Kiernan ]
[ December 12, 2008: Message edited by: terry Kiernan ]
Peter Lawrey
Ranch Hand

Joined: Dec 21, 2008
Posts: 62
Very few packages support SSL and non-blocking IO.
It is worth nothing that non-blocking IO adds some complexity to your code.
You may be better of with using blocking IO.
 
Don't get me started about those stupid light bulbs.
 
subject: Java.io Read blocking
 
Similar Threads
Can non-blocking IO be this simple?
Reading a properties file using BufferdInputStream
URL / URLConnections and setting timeouts
Reading from an Socket and it hands at in.readline()!=null
Please help with BufferReader.read()