Carlos Roque Code Hints, Examples and more

30Jun/113

Why I chose Silverlight over Flash for my FTP client

UPDATE: I have been having issues with silverlight sockets so this project hasn't been finished. If anyone had any luck with something like this please share your experience. Thanks


 

I made this File uploader that connects to an FTP server to upload customer files. My first instinct was to use flash and action script. The project went smoothly and development was rather easy, I was impressed by the simplicity of the Actionscript sockets. It turns out all that simplicity came at a price, just a few hours after deployment some users could not upload files, the app would hang and crash some browsers.

After a few minutes of researching I discovered that the files that caused this problem were large files. The size of the file that caused the problem was dependent on the system, older systems with small memory would crash with files that were 200MB while others could handle 1GB files.

as it turns out my problem was that Flash could not load a file partially. you pretty much have to load the entire file to memory to send it with a socket. then there is the problem that flash doesn't support any sort of bytesSent property of progress event handler.

While .net sockets don't support progress event handlers they do provide with the bytesSent property. also FileStream allows for the partial loading of a file. All this translates to two thing:

  1. I can read a file piece by peace, so now i can send 1GB files from any system.
  2. Since i can read a partial file I can now resume an interrupted upload.

Silverlight Sockets areĀ  harder to implement thought, since all receives and sends are asynchronous any method that updates the interface needs to be implemented as a delegate. You also need to keep track of the order in which messages arrive. A simple way is to block the application and make it wait for an eventComplete from the socket using and Autoevent.

So in conclusion I ended up using Silverlight for my FTP Client because of the flexibility that FileStream provided and even thought Sockets in Silverlight are more difficult to implement, now I have a more robust application for my customers.

P.S one bit of advise is that if you must receive and send messages at the same time in the same socket, use two socketEventArgs, one for sending and one for receiving

Filed under: ActionScrip, C# 3 Comments