some example to send big file from server to client?
Frederic Bregier
fredbregier at free.fr
Thu May 21 12:56:50 EDT 2009
Hi,
You will not read in one ChannelBuffer the full big file or you will have
for sure an Out of Memory exception.
So you have to split the read and write operation by chunk.
There are several ways to do that:
1) in your protocol by reading and writing by packet with a header length on
each packet
2) in your protocol by sending first the full size as a header than sending
by chunk the file like:
- while (read not finished) {
read in my ChannelBuffer a chunk
write this channelBuffer to the channel
}
3) In both cases (1 and 2) I would suggest you to use also the
channelInterestChanged to prevent further OOME like shown in the DISCARD
example. The idea is to first send some chunks and testing each time you
want to send one that the channel.isWritable(). If not, then just store your
next chunk and wait to be waking up by the channelInterestChanged call in
order to be able to continue to write again.
HTH,
Frederic
tantom wrote:
>
> my client program is c#,and now i use netty and write the client send big
> file to the netty server
> that's ok now.
>
> but now i am try to send big file from netty server to the client.
>
> i found the channel api, just and write(Object) method.
>
> if i write all the big file's bytes to the channelbuffer and call
> channel.write...may be....
>
>
>
-----
Hardware/Software Architect
--
View this message in context: http://n2.nabble.com/some-example-to-send-big-file-from-server-to-client--tp2952981p2953030.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list