Solved

unable to create I/O buffered from SocketChannel

Posted on 2002-05-29
8
719 Views
Last Modified: 2009-07-29
I open socketChannels to listen incoming
datagrams. However, It seems to me that
I can't create such as

BufferedReader rd = new BufferedReader(new InputStreamReader(Channels.newInputStream(socketChannel));

'cause... it will be a exception error when i
try to call "rd.readLine ()"

So, it is prohibit to do this, or did i do something
wrong ??
0
Comment
Question by:mrvithan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 7041271
 What is the exception you are getting? Can you post the whole stack trace?
0
 

Author Comment

by:mrvithan
ID: 7041294
Exception in thread "main" java.nio.channels.IllegalBlockingModeException
        at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:39)
        at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:92)
        at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:86)
        at java.io.InputStream.read(InputStream.java:88)
        at sun.nio.cs.StreamDecoder$ConverterSD.implRead(StreamDecoder.java:282)

        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:179)
        at java.io.InputStreamReader.read(InputStreamReader.java:167)
        at java.io.BufferedReader.fill(BufferedReader.java:136)
        at java.io.BufferedReader.readLine(BufferedReader.java:299)
        at java.io.BufferedReader.readLine(BufferedReader.java:362)
        at MSNClient$Session.getLine(MSNClient.java:153)
        at MSNClient$MSN.connect(MSNClient.java:85)
        at MSNClient.main(MSNClient.java:216)
Press any key to continue...
0
 
LVL 35

Expert Comment

by:girionis
ID: 7041298
 What is the exception you are getting? Can you post the whole stack trace?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:mrvithan
ID: 7041313
????
0
 
LVL 35

Accepted Solution

by:
girionis earned 100 total points
ID: 7041316
 Sorry pressed refresh accidentally.

  From the jdk1.4 documentation for the newInputStream method:

  "The read methods of the resulting stream will throw an IllegalBlockingModeException if invoked while the underlying channel is in non- blocking mode. The stream will not be buffered, and it will not support the mark or reset methods. The stream will be safe for access by multiple concurrent threads. Closing the stream will in turn cause the channel to be closed."

  I am not very familiar with the new I/O classes but from the documentation I assume that the channel you are trying to read from is in the incorrect blocking mode.

  Maybe someone else with more experience can help you.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7041342
try to create your SocketChannel in this manner:

sc = SocketChannel.open();
sc.configureBlocking(true); // that is what you must have
sc.connect(address);
0
 

Author Comment

by:mrvithan
ID: 7041351
well, i tried it also... and i got

Exception in thread "main" java.nio.channels.IllegalBlockingModeException
        at java.nio.channels.spi.AbstractSelectableChannel.register(AbstractSele
ctableChannel.java:173)
        at java.nio.channels.SelectableChannel.register(SelectableChannel.java:2
54)
        at MSNClient$MSN.connect(MSNClient.java:41)
        at MSNClient.main(MSNClient.java:216)

... Opps !!! any comment

acutally, i read this http://javaalmanac.com/egs/java.nio/NbClient.html.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7054983
 Thank you for the points. I am glad I helped :-)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question