Skip to content
Advertisement

Netty: TCP file transfer doesn’t work correctly

I am working on my online file storage and today I have encountered some issues with my Netty TCP file tranfer. So the problem is that only 8192 bytes of data is actually written in the file on the client-side. I want to know what the problem is, and how I can fix it.

I have seen ALL of the other (5) stackoverflow questions.

Here is my server bootstrap:

JavaScript

My server-handler:

JavaScript

My client bootstrap:

JavaScript

My client handler:

JavaScript

EDIT

The problem was that I removed the handler too quickly, then other packets got handled in other handlers/were dropped from the pipeline.

Advertisement

Answer

The problem is indeed most likely to be in your FileChunkHandler.

You only read a single buffer (likely containing 8192 bytes – 8kB), and then remove the handler. The remaining chunks either get “handled” by some other handler in the pipeline, or reach the end of the pipeline and get dropped. As mentioned in Discord, you need to keep track of how many bytes you are expecting, subtract the number received, and only when that number reaches 0, should you remove the handler.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement