mina 框架如何发送字节数组

playboylee 2008-07-01 12:20:10
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)
...全文
2319 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
cj111234 2012-10-22
  • 打赏
  • 举报
回复
cj111234@163.com 求一份
xuguiyi100 2012-03-22
  • 打赏
  • 举报
回复
我也遇到这个问题的,有的能发一份给我的吗?xgurry@126.com
wind_fzsh 2012-02-16
  • 打赏
  • 举报
回复
发一份给我吧?遇到这样的问题wind_fzsh@163.com
misters 2012-02-13
  • 打赏
  • 举报
回复
发一份给我吧?遇到这样的问题honeyfinsh@hotmail.com
yaingsoul 2011-10-24
  • 打赏
  • 举报
回复
这么多人想要,你为什么不直接贴出来呢?
liuxu8083 2011-09-17
  • 打赏
  • 举报
回复
我也遇到了棘手啊,还能帮助我吗?邮箱13622058276@139.com 谢谢
hanyu332 2011-06-13
  • 打赏
  • 举报
回复
我也遇到这个问题了。。这都过了好几年了,如何解决的,谢谢 邮箱:361806691@qq.com
huxinlong 2011-05-25
  • 打赏
  • 举报
回复
没有设置编码的原因,你加上这句试试:
NioSocketAcceptor acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
  • 打赏
  • 举报
回复
我也遇到这个问题了。。谢谢 邮箱:361806691@qq.com
sbgphl 2010-02-08
  • 打赏
  • 举报
回复
我也遇到这个问题了,如果解决的呀,希望你能帮助我。

piaohailin@gmail.com msn:phlsbg@msn.com
jianmao06 2009-08-13
  • 打赏
  • 举报
回复
你好,我非常的需要你这个解决办法,希望你能帮助我,QQ 240835726 MSN jianmao334@live.cn 邮箱jianmao334@yahoo.com.cn
kazy0514 2009-05-06
  • 打赏
  • 举报
回复
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);
ll_100 2008-12-01
  • 打赏
  • 举报
回复
lilong_1985@126.com

好啊! 我为什么总报下面的异常啊。 请问下如何维持多个客户端的连接啊?? 急。。

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)
yukikaze 2008-11-08
  • 打赏
  • 举报
回复
我也想知道,邮箱是yukikaze77@gmail.com
谢谢
userdaye 2008-08-26
  • 打赏
  • 举报
回复
哥们告诉我一下怎么发送byte数组,还有就是 你的客户端和服务器端都是用的什么过滤器,为什么mina里面不用过滤器就只能够建立连接却不能够进行数据的交互。???我的邮箱pengli.bj@163.com 谢谢了
islandnenu 2008-07-28
  • 打赏
  • 举报
回复
能告诉我你是怎么解决的吗?
我的邮箱4kghost@163.com
playboylee 2008-07-15
  • 打赏
  • 举报
回复
已经自己解决,需要者留言
playboylee 2008-07-02
  • 打赏
  • 举报
回复
请懂MINA框架的朋友帮忙,MINA是好框架,但发不了字节数组吗?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧