Solved

unable to create I/O buffered from SocketChannel

Posted on 2002-05-29
8
710 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
  • 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
 

Author Comment

by:mrvithan
ID: 7041313
????
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now