我的服务器为客户端提供套接字服务。我的服务器DecoderHandler
从FrameDecoder
. 当我的客户端向服务器发送小数据(小于约 1024 字节)时,服务器成功解码,但是当我的客户端尝试将图像的内容写入服务器时,出现 index-out-bound-exception .
我猜解码器选择的缓冲区必须有大小限制。于是我打印出了参数——buffer的类。
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
ChannelBuffer buffer) throws Exception {
System.out.println(buffer.getClass());
return null;
}
结果是:
class org.jboss.netty.buffer.BigEndianHeapChannelBuffer
我想问一下:我可以将缓冲区的类型从更改BigEndianHeapChannelBuffer
为DynamicChannelBuffer
,以便我可以通过套接字传输图像。或者有没有人可以提供其他有效的方法来帮助解决我的“通过netty通过套接字传输大数据”的问题。
我真的需要你的意见。再次感谢!
来自服务器的堆栈跟踪:
java.lang.IndexOutOfBoundsException
at org.jboss.netty.buffer.AbstractChannelBuffer.checkReadableBytes(AbstractChannelBuffer.java:657)
at org.jboss.netty.buffer.AbstractChannelBuffer.readBytes(AbstractChannelBuffer.java:337)
at org.jboss.netty.buffer.AbstractChannelBuffer.readBytes(AbstractChannelBuffer.java:343)
at com.netty.www.codec.MessageDecoder.receiveChatInfoBeanFromClient(MessageDecoder.java:422)
at com.netty.www.codec.MessageDecoder.decode(MessageDecoder.java:70)
at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:282)
at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
12/09/26 09:12:09 INFO server.MessageServerHandler: The user's channel is closed:
来自客户端的堆栈跟踪:
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.write(Unknown Source)
at neusoft.socket.TCPClient.writeBytes(TCPClient.java:217)
at neusoft.socket.TestChatNew.sendChartMedia(TestChatNew.java:185)
at neusoft.socket.TestChatNew.main(TestChatNew.java:36)