开发者

Use the underlying Socket/ServerSocket in a SocketChannel/ServerSocketChannel?

I'm trying the Java.nio-package for non-blocking communication. So I got my ServerSocketChannel and all my connected clients (SocketChannel) in a Selec开发者_开发百科tor and wait for data (OP_ACCEPT/OP_READ) using Selector.select().

My question is: Can I - instead of using a ByteBuffer and read directly with SocketChannel.read() - use the underlying Socket, get an InputStream and read using that stream? Or will that mess up the selector-stuff?


You can't.

http://download.oracle.com/javase/1.4.2/docs/api/java/net/Socket.html#getInputStream%28%29

If this socket has an associated channel then the resulting input stream delegates all of its operations to the channel. If the channel is in non-blocking mode then the input stream's read operations will throw an IllegalBlockingModeException.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜