mina 框架用来做NIO,挺方便,但是如何才可以发送字节数组呢?接收没问题的.小弟是这样做的
                int blen = Pkg.createLoginRespPackage(1).length;
                System.out.println("------------------------> len:" + blen );
                ByteBuffer buf = ByteBuffer.allocate( blen ) ;
                if(buf!=null){
                    System.out.println("send...");
                    //buf.clear();
                    //bb.get(Pkg.createLoginRespPackage(1));
                    buf.put( Pkg.createLoginRespPackage(1) );
                    //buf.put((byte) '.');
                    buf.flip();
                    //session.write(bb.duplicate());         //发送验证包
                    session.write(buf);         //发送验证包
                    //buf.clear();
                }但是出现如下异常:java.lang.IllegalStateException: Don't know how to handle message of type 'java.nio.HeapByteBuffer'.  Are you missing a protocol encoder?
at org.apache.mina.common.AbstractPollingIoProcessor.flushNow(AbstractPollingIoProcessor.java:536)
at org.apache.mina.common.AbstractPollingIoProcessor.flush(AbstractPollingIoProcessor.java:469)
at org.apache.mina.common.AbstractPollingIoProcessor.access$500(AbstractPollingIoProcessor.java:43)
at org.apache.mina.common.AbstractPollingIoProcessor$Worker.run(AbstractPollingIoProcessor.java:681)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【playboylee】截止到2008-07-01 12:20:11的历史汇总数据(不包括此帖):
    发帖数:4                  发帖分:80                 
    结贴数:3                  结贴分:60                 
    未结数:1                  未结分:20                 
    结贴率:75.00 %            结分率:75.00 %            
    楼主加油
      

  2.   

    请懂MINA框架的朋友帮忙,MINA是好框架,但发不了字节数组吗?
      

  3.   

    哥们告诉我一下怎么发送byte数组,还有就是 你的客户端和服务器端都是用的什么过滤器,为什么mina里面不用过滤器就只能够建立连接却不能够进行数据的交互。???   谢谢了
      

  4.   

    我也想知道,邮箱是[email protected]
    谢谢
      

  5.   

    [email protected]好啊!  我为什么总报下面的异常啊。  请问下如何维持多个客户端的连接啊?? 急。。java.lang.IllegalStateException: Already released buffer.  You released the buffer too many times.
    at org.apache.mina.common.SimpleByteBufferAllocator$SimpleByteBuffer.release(SimpleByteBufferAllocator.java:81)
    at org.apache.mina.util.ByteBufferUtil.releaseIfPossible(ByteBufferUtil.java:39)
    at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageSent(AbstractIoFilterChain.java:581)
    at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageSent(AbstractIoFilterChain.java:320)
    at org.apache.mina.common.support.AbstractIoFilterChain.access$1200(AbstractIoFilterChain.java:53)
    at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageSent(AbstractIoFilterChain.java:653)
    at org.apache.mina.filter.LoggingFilter.messageSent(LoggingFilter.java:97)
    at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageSent(AbstractIoFilterChain.java:320)
    at org.apache.mina.common.support.AbstractIoFilterChain.access$1200(AbstractIoFilterChain.java:53)
    at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageSent(AbstractIoFilterChain.java:653)
    at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java:222)
    at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(ExecutorFilter.java:264)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
    at java.lang.Thread.run(Thread.java:619)
      

  6.   

    IoBuffer b = IoBuffer.allocate(100);
    b.putShort((short) 18);// len
    String str ="Hello";
    ByteArrayOutputStream outputPacket = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(outputPacket);
    dos.writeUTF(str);
    dos.flush();
    b.put(outputPacket.toByteArray());
    b.flip();
    session.write(b);
      

  7.   

    你好,我非常的需要你这个解决办法,希望你能帮助我,QQ 240835726  MSN [email protected]  邮箱[email protected]
      

  8.   

    我也遇到这个问题了,如果解决的呀,希望你能帮助我。[email protected]   msn:[email protected]
      

  9.   

    我也遇到这个问题了。。谢谢 邮箱:[email protected]
      

  10.   

    没有设置编码的原因,你加上这句试试:
    NioSocketAcceptor acceptor = new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
      

  11.   

    我也遇到这个问题了。。这都过了好几年了,如何解决的,谢谢 邮箱:[email protected]
      

  12.   

    我也遇到了棘手啊,还能帮助我吗?邮箱[email protected] 谢谢
      

  13.   

    发一份给我吧?遇到这样的问题[email protected]
      

  14.   

    发一份给我吧?遇到这样的问题[email protected]
      

  15.   

    我也遇到这个问题的,有的能发一份给我的吗?[email protected]