You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Robin Batra <ro...@gmail.com> on 2007/04/16 23:27:20 UTC
Query
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
Re: Query
Posted by Trustin Lee <tr...@gmail.com>.
On 4/17/07, Robin Batra <ro...@gmail.com> wrote:
> 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:
It seems like you didn't add a ProtocolCodecFilter. Please check the
Main class in the quick start guide.
> And one more question
> can i write my custom objects into org.apache.mina.common.ByteBuffer and
> send it using session.write();
Sure. You will have to use a ProtocolCodecFilter. Please refer to
SumUp example or HTTP server example in the documentation page.
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6