Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

unable to create I/O buffered from SocketChannel

Posted on 2002-05-29
8
Medium Priority
?
731 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

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

Accepted Solution

by:
girionis earned 300 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

636 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