Thanks Jim,
But I have set socketChannel.configureBlocking(false);
when I used
ObjectInputStream ois = new ObjectInputStream(Channels.newInputStream(socketChannel));
Object obj = ois.readObject();
I got the following exception
java.nio.channels.IllegalBlockingModeException
currently what I have done is
while (selector.select(500) > 0)
{
// Get set of ready objects
Set readyKeys = selector.selectedKeys();
Iterator readyItor = readyKeys.iterator();
// Walk through set
while (readyItor.hasNext())
{
// Get key from set
SelectionKey key = (SelectionKey) readyItor.next();
// Remove current entry
readyItor.remove();
// Get channel
SocketChannel keyChannel = (SocketChannel) key.channel();
if (key.isConnectable())
{
// Finish connection
if (keyChannel.isConnectionPending())
{
while (!keyChannel.finishConnect())
{
}
}
// Send request
keyChannel.write(encoder.encode(CharBuffer.wrap(request)));
}
else if (key.isReadable())
{
// Read what's ready in response
keyChannel.read(buffer);
buffer.flip();
// Decode buffer
decoder.decode(buffer, charBuffer, false);
// Display
charBuffer.flip();
String str = charBuffer.toString();
System.out.println(str);
// Clear for next pass
buffer.clear();
charBuffer.clear();
}
else
{
System.err.println("Ooops");
}
}
when I print the charBuffer I can see the object code of the
java object sent through the stream.
But I am still unable to reconstruct the java object out of the ByteBuffer or the CharBuffer