How many times is the messageReceived() Method invoked when I send large data?

"이희승 (Trustin Lee)" trustin at gmail.com
Thu Aug 26 00:07:55 EDT 2010


If the large data is a file, refer to FileRegion.  Otherwise, give
ChunkedWriteHandler and ChunkedInput a try.

HTH,
T

On 08/26/2010 12:45 PM, sinogermany wrote:
> 
> Hi both,
> 
> the problem was perfectly solved. Thank you so much for the quick replies.
> 
> here's the codes I added:
> server side:
> 
> private int size = -1;
> 						
> @Override
> protected Object decode(ChannelHandlerContext ctx, Channel channel,
> ChannelBuffer buffer){
>     if(size < 0 && buffer.readableBytes() > 0){
>         size = buffer.readInt();
>     }
> 							
>     int bytesRead = buffer.readableBytes();
>     if(bytesRead < size){
>         return null;
>     }else{
>         return buffer.readBytes(size);
>     }
> }
> 
> 
> 
> 
> 
> client side:
> ChannelBuffer bufferToWrite =
> ChannelBuffers.directBuffer(buf.readableBytes()+4);
> bufToWrite.writeInt(buf.readableBytes());
> bufToWrite.writeBytes(buf);
> channel.getChannel().write(bufToWrite);
> 
> 
> 
> 
> Now I can transfer really large binary data.
> 
> I still got two small questions:
> 1. on the client side, is there a way to "insert" the size to the first 4
> bytes in the "buf" object (like an "ArrayList") ? Calling a new
> channelbuffer object costs twice so much memory.
> 
> 
> 2. When several clients write large streams simultaniously, there should be
> several instances of my Decoder, right? I mean a part of request A should
> not be stimulated into the buffer of request B.
> 
> 
> Anyway, big problem solved, so thank you very much again!
> 감사합니다

-- 
what we call human nature in actuality is human habit
http://gleamynode.net/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 293 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100826/d96f6b02/attachment.bin 


More information about the netty-users mailing list