Solved

unable to create I/O buffered from SocketChannel

Posted on 2002-05-29
8
713 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reverse digits of a number using for loop 5 41
expectj telnet failing 5 36
use lov values 2 50
servlet web applications   metadata-complete="true" or false 3 40
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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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.

777 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