I read the quick start guide for MINA on mina.apache.org and it stated:
import java.util.Date;
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
public class TimeServerHandler extends IoHandlerAdapter {
public void exceptionCaught(IoSession session, Throwable t) throws
Exception {
t.printStackTrace(); session.close();
}
public void messageReceived(IoSession session, Object msg) throws
Exception {
String str = msg.toString();
if( str.trim().equalsIgnoreCase("quit"))
session.close();
Date date = new Date();
session.write( date.toString() );
System.out.println("Message written...");
}
public void sessionCreated(IoSession session) throws Exception {
System.out.println("Session created...");
if( session.getTransportType() == TransportType.SOCKET )
((SocketSessionConfig) session.getConfig()
).setReceiveBufferSize( 2048 );
session.setIdleTime( IdleStatus.BOTH_IDLE, 10 );
}
}
in the code it is shown that a string object can be written using
session.write()
but when i try to to do so, it says
java.lang.IllegalStateException: Write requests must be transformed to class
org.apache.mina.common.ByteBuffer:
And one more question
can i write my custom objects into org.apache.mina.common.ByteBuffer and
send it using session.write();;
thanks in advance