Jeroen Brattinga thank you for your instructions
But no matter MessageDecoderResult is OK or NOT,even the first
statement:System.out.println(some characters) had not be reached.It's so
confused!
----- Original Message -----
From: "Jeroen Brattinga" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, October 11, 2006 5:11 PM
Subject: Re: I cann't work with ProtocolCodecFilter normally,asking for your
help!!
You should look closer to the SumUp example. But in a nutshell it comes
down
to this:
- for every incoming data the decoder classes are called
- for every decoder class the --decodable-- method is checked. If the
return
value is MessageDecoderResult.OK then the --decode-- method is called.
- the --decodeBody-- method is never called from the framework (!), but in
the SumUp example it is called from the --decode-- method from the
abstract
class (to provide easier subclasses that only have to implement the
--decodeBody-- method.
In your case you have forgotten to return the MessageDecoderResult code
and
don't call the --decodeBody-- method from the --decode-- method.
Jeroen Brattinga
2006/10/11, 凌晨 <[EMAIL PROTECTED]>:
Hello Everyone:
I cann't work with ProtocolCodecFilter normally,asking for your help!!
First the add filter in Main Class code segment:
public static void main(String[] args) throws Exception
{
acceptor = new SocketAcceptor();
IoAcceptorConfig config = new SocketAcceptorConfig();
((SocketAcceptorConfig) config).setReuseAddress(true);
config.setDisconnectOnUnbind(true);
config.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new ServerProtocolCodecFactory()));
acceptor.bind(new InetSocketAddress(PORT), new ProtocolHandler(),
config);
System.out.println("Listening on port " + PORT);
}
Second The AbstractStringDecoder
public abstract class AbstractStringDecoder implements MessageDecoder
{
protected AbstractStringDecoder()
{
System.out.println("AbstractStringDecoder");
}
public MessageDecoderResult decodable(IoSession session, ByteBuffer in)
{
System.out.println("decodable");
}
public MessageDecoderResult decode(IoSession session, ByteBuffer in,
ProtocolDecoderOutput out) throws Exception
{
System.out.println("333");
}
protected abstract String decodeBody(IoSession session, ByteBuffer in);
}
The Third StringDecoder
public class StringDecoder extends AbstractStringDecoder
{
public StringDecoder()
{
System.out.println("decode");
}
public String decodeBody(IoSession session, ByteBuffer in)
{
System.out.println("111");
}
public void dispose() throws Exception
{
System.out.println("333");
}
public void finishDecode(IoSession arg0, ProtocolDecoderOutput arg1)
throws Exception
{
System.out.println("222");
}
}
Then the ServerProtocolCodecFactory
public class ServerProtocolCodecFactory extends
DemuxingProtocolCodecFactory
implements ProtocolCodecFactory
{
public ServerProtocolCodecFactory()
{
super.register(StringDecoder.class);
super.register(StringEncoder.class);
}
}
But When I send Message to the server,StringDecoder.decodeBody() never be
invoked.I biult the server on MINA1.0 JDK1.5
Thanks In Advance!
--
Jeroen Brattinga