
During my AS3 session in July at the Flash Festival I talked about loading assets at runtime, with sockets, since we have binary sockets now, we can send any binary stream we want into the player, since it's a valid stream for the flash.display.Loader class, we can save the incoming bytes into a ByteArray then interpret the content with the Loader.loadBytes() method.
Hence, assets loaded through a socket connection will not be cached by the browser
I developped a little Socket browser in C#, and a client tool in AS3, just start the Socket browser, connect the Flash client to the socket browser with the correct IP (copy paste the IP given by the Socket Browser), then select a valid file (bitmap, or swf), then the stream will be sent to the Flash client, and you should be able to see it
If you want to load several files, you will have to close the Socket Browser and also the Flash client, and restart them, some little bugs to be fixed soon
Download the sources here
In case you don't have .NET framework, you can download it here
Comments (31)
Sweet demo.
Do you know if it’s possible to have flash act as a socket client AND SERVER?
basically… (and i think not, but i wish/hope is possible) is it possible to write a socket server in AS3? – imagine being to share files between two flash files without having a server. now, that! would be sweet.
this is not possible as far as i know
No you can’t. You’d need listening sockets which you can not create with AS3.
This is the coolest thing I have seen thus far from AS3. Very powerful stuff. May I use this code freely?
hi hendrix,
yes you can use it, of course
I think I’m doing something wrong. When I run the socket server on my local pc I get ::1 on port 12000 in th ebottom window. (I installed .NET version 2)
If I type 1 into the socket server field of the Flash client on my local system I get sandbox violations (local with file system not permitted to use sockets). I also get cross domain sandbox violations if I upload it to a webserver.
I guess I don’t fully understand where to put the files and how to run them.
Question 1 :
Where do put the C# socket server?
Question 2:
Where do I put the Flash file?
Question 3:
What adjustments do I need to make to overcome the security violations?
Question 4:
Should the socket server be putting out something besides ::1 on port 12000 ?
Thanks for all of your help.
hi hendrix,
question 1 : the socket server is launched on localhost on a ip that is automatically found by the application on port 12000
question 2 : the flash file, can be anywhere on your computer, the idea would be to run a socket server online, that would stream SWF available on your server, but for the demo, let’s send SWF on your hard disk
question 3 : you have to check first, if Window for instance is not blocking the Socket Server (firewall) so check that first, usually when you start first the application, Windows opens a window asking for blocking or not the application, another thing to check is the Security SandBox type running with your player.
question 4 : there is nothing for me to do usually, just check that the server can run, by connecting to it through telnet for example, next check your security sandbox type, from flash.system.Security.sandboxType and make sure you have this value “localTrusted”
cheers
let me know !
Thanks for the advice.
I have gotten it to work an a different pc. I isolated the problem to be in how the socket server interacts with my wireless router. I am still trying to work around it. Any chance you will make the socket server source available?
Thanks
Clu
Another way to overcome the security violations that question 3 asks about is with a Flash Player trust file. On my Win machine, it’s in C:\Documents and Settings\[USER]\Application Data\Macromedia\Flash Player\#Security\FlashPlayerTrust. The document at http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=1165eb90 talks about how to create them. Look under the heading “Trust Files”.
Ali
interesting,
tks Ali
Migs write: Sweet demo.
Do you know if it’s possible to have flash act as a socket client AND SERVER?
LocalConnection would do this. You could send the binary data over a LocaConnection to another .swf running on the same machine.
Hi spender,
No you can’t, you would need listening sockets for that.
Concerning the LocalConnection thing, you could send some binary data, but you can’t send more than 40kb through it. Which is quite limitating.
Is there a way to send “byteArray” from flash to a host application (to a c# application in my example) ?
Hi scriptMan,
yes it is possible very easily with the different methods from the flash.net.Socket class
have a look here :
http://livedocs.adobe.com/flex/201/langref/flash/net/Socket.html
cheers
Hmm, that’s quite good
I’ll try this method, but, i wonder if i can make it by External Interface?
Either way, i just want to send a byteArray to my desktop host application, and get a jpeg from it
scriptMan, in Flash you can encode the byteArray as a base64 using this class http://www.dynamicflash.com/goodies/base64
then you can send it via ExternalInterface and decode it to a byteArray in your c# app
Does anyone know what happened to the source code?
I would like to know if anyone has the source code.
Hi guys,
I will re-upload the sources tonight !
kind regards
Thibault
Link to sources is still broken
Hi. I have a project where we need this.
I could pay for the help.
kindly regards
Henrik
Thanks for your work. It would be great if you could upload the sources. Best regards, Christian Lehmann
Source still down?
And yes thank you very much for you work, this stuff is very interesting and I have been doing a lot of research on this stuff but can’t find much to get me on the right track.
Great article, by the way, but it appears that the link to the source code you’ve provided is not working. If you would, it would be great to see which direction you’re heading in with the socket code.
No source here..
Hi Ms,
I will re-upload the sources tonight
stay tuned,
best,
Thibault
No source…?
Very interesting stuff, but the link to the sources seems broken…
Hi Thibault,
I will update that tonight, sorry about that !
Thibault
Sadly the links are still down. I’m also interested in how you did it.