Flex socket sucks

Image via Wikipedia

We needed to build a Flex based FTP upload client. With socket support and the help of ActionScript 3 this should be pretty easy.

However I was very surprised to see that this was not at all easy. Flushing data from the socket is non-blocking. This means that you send the data and don’t get any feedback when the data is done.

The FileStream class however seems to have solved this with OutputProgressEvent. Why not Sockets?

So to build our FTP client we needed to split the data and send it chunk by chunk and loop through it. This is a really bad solution as we need to be absolutely sure that the previous chunk is done before sending the next. This means that that any upload will be extremely slow.

If you read this and feel you have a workaround please share.

BTW: This behavior is reported as a bug at Adobe (read more)

Reblog this post [with Zemanta]

One Reply to “Flex socket sucks”

  1. Indeed. I implemented some socket code today and quickly became frustrated with the poor socket implementation. FileReference has an upload method, and it dispatches a progress event. I’ve been implementing a bulk file uploader/image resizer, and since my code resizes the images, I need to modify the data before uploading. Since FileReference doesn’t allow the data to be modified even in memory (for some stupid reason), I decided to implement my own socket code to upload. Well, I quickly found that I cannot get the status of the upload. The progress event evidently fires when the upload is complete, which does no good on large files. What a load of crap flex sockets are!

Comments are closed.