File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes NIO Channels Object Transfer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "NIO Channels Object Transfer" Watch "NIO Channels Object Transfer" New topic

NIO Channels Object Transfer

merwin pinto
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
i was trying this test code given below, for transfer of objects thru NIO Channels..
Everything working fine but at the point when i try to create a ObjectOutputStream ...using the SocketChannel ... i get an error saying ::->
java.nio.channels.IllegalBlockingModeException .
i really dont understand why this happens ...
is there any thing wrong that i am doin?.....
Please Help Me ....

Thanks A Lot
HERE is the CODE

import java.nio.*;
import java.nio.channels.*;
import java.util.*;

public class DateServerNIO {
static final int port = 1313;

void process() throws IOException {

ServerSocketChannel serverChannel =;
serverChannel.socket().bind(new InetSocketAddress(port));
System.out.println("Socket bound");
Selector mux =;
serverChannel.register(mux, SelectionKey.OP_ACCEPT);
System.out.println("Channel registered");

while ( > 0) {
Iterator keyIt = mux.selectedKeys().iterator();
while (keyIt.hasNext()) {
SelectionKey key = (SelectionKey);
if (key.isAcceptable()) {
ServerSocketChannel server =(ServerSocketChannel);
SocketChannel channel = server.accept();
if (channel != null) {
// channel.configureBlocking(false);
// channel.register (mux, SelectionKey.OP_READ);
ObjectOutputStream dateOut =new OutputStream
(Channels.newOutputStream (channel));
//Here is where the problem comes
dateOut.writeObject(new Date());
Yin Jintao

Joined: May 11, 2005
Posts: 1
public static OutputStream newOutputStream(WritableByteChannel ch)Constructs a stream that writes bytes to the given channel.
The write 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. The stream will be safe for access by multiple concurrent threads. Closing the stream will in turn cause the channel to be closed.

ch - The channel to which bytes will be written
A new output stream
I agree. Here's the link:
subject: NIO Channels Object Transfer
It's not a secret anymore!