How many times is the messageReceived() Method invoked when I send large data?
sinogermany
sinogermany at gmail.com
Wed Aug 25 23:45:08 EDT 2010
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!
감사합니다
--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/How-many-times-is-the-messageReceived-Method-invoked-when-I-send-large-data-tp5463771p5464114.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list