UDP File Transfer - Recap
Here's a screenshot of it in action using a tinier version of my test file of choice. Using SFTP took around a 14 seconds to transfer the video, whereas it took about 9 using the application we built. There are many reasons SFTP was slower in this case, but I'll leave that to you to figure out.
With every other project that we've made so far, there are some deficiencies and improvements we could make. Let's analyze a few of them:
- This program can sure take up a lot of heap memory. When I was testing it with a larger file I had some
OutOfMemoryExceptions thrown at me. What we should be doing instead is saving the
Blocks to the disk (instead of storing them in memory) as we send and receive them.
- The Sender needs some better client management. Say if a second (malicious) client were to connect and send a
BYEmessage in the middle of a transfer, it would stop the transfer with the first. The first Receiver wouldn't even know what's going on, it would just keep queuing up block requests. The Sender really should ignore any datagrams from other clients when its in the middle of a transfer with one.
- Timeouts & Retries. This one is so important I'm putting in bold, underlined, italicized and red text. Our code is completely void of any timeouts and retries (except for Block requeueing). When one of the apps is waiting for an
ACK, it should wait for a set amount of time and then resend its
Packetin case the original one was dropped. In the real world (and future applications) we need to be adding in our own retries and timeouts for the control
- In fact the
Blockrequeueing method is pretty bad. It should wait for a set amount of time first before making another request for a block. When I first tested this over the internet, my Receiver created many
REQBs before the Sender could even respond to the first one it got.
- In fact the
Keep in mind that this is supposed to be a sample application showcasing UDP (and not a real world one). If you were to add in UDP based file transfer to any application you are building, you would really need to make these changes.
As always, if you spot any other issues, be sure to send me an email and I'll evaluate them. Anything is appreciated.