It's not a secret anymore!
The moose likes I/O and Streams and the fly likes Read blocking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark " Read blocking " Watch " Read blocking " New topic
Author 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

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 however i need to use BufferedInputStream from

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( "", "ssl");

and i got this in my output when i was calling the 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.
I agree. Here's the link:
subject: Read blocking
It's not a secret anymore!