Sending large files
Christian Migowski
chrismfwrd at gmail.com
Tue Jun 2 03:20:07 EDT 2009
Hi,
my 2 cents: The code looks ok and the approach to send the file in
chunks and send a special "end of file" message also seems reasonable
to me.
The "end command" is actually sent (i.e. you see the "end chunk data"
log msg), right?
There is only one possibility left if no exceptions occur during the
execution of your code (you are using tcp, right?):
The server does not understand your "end command". Is the format of
the end command you are sending really correct? Is it also your
server, can you check if the decoding of the end message is also
working when the srv is in "de-chunking mode"?
If you think it is all correct you could check if the message is
actually received on the server using Wireshark or your preffered
network sniffer, but if no exceptions occured it should.
hope this helps a little,
regards,
christian!
On Tue, Jun 2, 2009 at 8:06 AM, Jiang Bian <timobj at gmail.com> wrote:
>
> Long story short, one part of my project requires to send large files using
> netty. The large is split into small chunks, and at the end, the client is
> suppose to send a "end command" signal. The problem is the "end command"
> never gets to the server, when sending big files (20MB).
>
> Here is my code for the sendFile funciton.
>
> private void sendFile(MessageEvent e) throws InterruptedException {
>
> ChannelFuture lastWriteFuture = null;
>
> int count = wrappedFile.getSegmentCount();
>
> int sleepTime = SystemConfigHelper.getSystemConfigHelper()
> .getSleepTime();
>
> int i = 0;
> while (e.getChannel().isWritable() && i < count) {
> for (; i < count; i++) {
> // logger.info("sending segment " + i);
> Chunk chunk = wrappedFile.getChunk(i);
> // logger.debug("sending: " + chunk.getMD5String());
> // logger.debug("length: " + chunk.getPayload().length);
> ChannelBuffer buffer = JigDFSProtocolRequestFactory
> .chunkData(chunk);
>
> this.bytesSent.addAndGet(buffer.capacity());
>
> lastWriteFuture = e.getChannel().write(buffer);
>
> try {
> Thread.sleep(sleepTime);
> } catch (InterruptedException ex) {
> ex.printStackTrace();
> throw new InterruptedException(ex.getMessage());
> }
>
> }
> }
>
> // Wait until all messages are flushed before closing the channel.
> if (lastWriteFuture != null) {
> lastWriteFuture.awaitUninterruptibly();
> }
>
> logger.debug("end chunk data");
>
> logger.debug("write end_chunk_data command");
>
> lastWriteFuture = e.getChannel().write(
> JigDFSProtocolRequestFactory.endChunkData());
>
> // Wait until all messages are flushed...
> if (lastWriteFuture != null) {
> lastWriteFuture.awaitUninterruptibly();
> }
>
> logger.info("file sent...");
>
> }
>
> It works fine with small files. So, my question basically is: what's the
> right way to ensure a message gets to the server on the client side?
> Hope I am not making stupid mistakes here.
> Please let me know if you need any other information.
>
> Thanks,
>
> Jiang
> --
> View this message in context: http://n2.nabble.com/Sending-large-files-tp3010547p3010547.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
More information about the netty-users
mailing list