Preface: This is a bad idea with untested code. If you deploy it on a production server bad things will happen.
I sniped the browser detection code from Quirksmode and it seems to work fairly well. The rest of the code is below:
The trickiest part of getting this to work was Adobe’s insane rules for allowing their Socket classes to connect to servers. In order for the client to successfully connect to the server you need to serve a XML policy file from port 843. Additionally, this file can’t be served by a HTTP server but must be a custom server that only spits back the file along with a null carriage return. A detailed description of this abortion is here http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html
This really posses two problems. One, you need to be running some random “policy file server” for Flex sockets to be of any use. And two, since 843 is a privileged port, this server can’t be started by a regular user.
Anyway, I tested this on IE7+ and it seemed to work decently well. Per the warning on top I don’t want to leave this running on a live server anywhere.
If you want to get it to actually run, do the following:
What’s in the box:
Credits: I borrowed the WebWorker SHA1 implementation from John Resig who adapted it from Ray C Morgan.
So here is another crazy idea. Instead of executing the WebWorker code on the server, would it be possible to dynamically make the WebWorker code re-entrant using setTimeout() on the client where loop structures exist?
Posted In: Demo