I could not find a single way to have real sockets in Javascript. Google told me that there probably is no solution except embeding a java applet or an active-x component! So I thought why not using a little .swf file as a bridge from javascript to the socket functions of flash!
You can see the result here: http://dev.dschini.org/socketjs/
This works pretty neat, fast and stable! The client connects to a patched (”\0\n”) Unreal IRCD. Except connecting and joining a channel there is no much functionality, but it works pretty good!
If you are interested then get your version at http://thinkforge.org!
Nice idea…
for long run socket connection it will be helpful…
regards
does not work in moziall/firefox
js error in line 93:
window.document.socket.SetVariable is not a function
… SetVariable will not work – you have to try something like http://osflash.org/flashjs or external api of falsh 8 http://www.adobe.com/devnet/flash/articles/external_interface.html
mfg
Works just fine for me in Firefox.
is it possible to have your script hosted on http://www.mywebsite.com and send a socket to antoher server named http://www.other.com ?
I tried your script but without success. The flash result in the „SocketOnConnect“ function always return „false“ :-( (I didn’t change the flash file, as I don’t have flash – I mean the software).
Hi jon, a socket client in flash only can connect to the same host. Regards Manfred
Sockets from JavaScript? Is this idea not frightening to anyone else? Am I the only one who thinks maybe there are some things JavaScript was never meant to do?
Although, considering you had to mix in Flash, I guess JavaScript can’t really do sockets… still… *shiver*
Do you shiver at Flash doing it? If Flash, which is easily reverse engineered, should be capable of it, why not JavaScript? For me, the idea’s actually pretty exciting, because I can keep all the constraints in the server and cut out the middleman of Perl for most things.
Simply put, web apps are the future: they’re relatively easy to build, implement and distribute; they’re os and hardware independant; and they’re becoming more and more powerful. With HTML 5 on the horizon the need for third party (corporate) contolled plugins like flash and silverlight could even drop away… leaving the technology in the hands of the developers themselves rather than some beaurocratic organization. That’s the goal.
You can do cross-domain socket calls if the receiving side has a crossdomain.xml file that allows it.
See http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_14213
Also see http://www.aflax.org which has provided javascript access to Flash objects including the sockets stuff for some time now.
Interesting.
I don’t have a Flash IDE to open the .fla source file, but it looks like you’re using the XMLSocket API. How do you use it to send generic messages, rather than only XML messages?
The XMLSocket API: http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary860.html
@michael
javascript has had sockets for quite some time, its called xmlhttprequest which makes a socket connection back to the server.
As long as the sandbox only allows it to connect to the originating server just as in xmlhttprequest then it poses the same security risk as ajax apps.
the title of this article is misleading as its not a true javascript solution. Firefox allows true javascript sockets via extensions. Otherwise you could have just used all flash to do the same thing that a million sites are already doing with flash sockets.
Hi! Cool library you’ve created.
You should use the dojo.flash layer to do your JavaScript/Flash communication, which I use on my Dojo Storage library. Here’s what you get if you use Dojo Flash:
* Support across IE, Firefox, and Safari
* Fast, Fast, Fast transfer both ways across the boundry
* Reliable transfer of data that won’t get corrupted by things such as the serialization bugs in ExternalInterface, for example
* Automatic installation and upgrade of Flash on the browser to work correctly
* Best of all, you don’t have to roll this stuff yourself :) Plus theres alot more of cool stuff it does for you (for example, it lets you feel like your calling methods from both sides, rather than using the cryptic fscommands and SetVariable ways of doing things)
Fast, reliable, cross-browser/platform Flash/JS communication is alot harder than Macromedia admits; Dojo Flash makes it easier. Email me if you have questions.
Best,
Brad Neuberg
Dojo Storage/Dojo Flash Maintainer
Interesting.
I don’t have a Flash IDE to open the .fla source file, but it looks like you’re using the XMLSocket API. How do you use it to send generic messages, rather than only XML messages?
The XMLSocket API: http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary860.html
Delete | Permalink
Neat idea, but I’m afraid that demo no longer works. I tried implementing it, but with the new security stuff in Flash, you can’t handle queries unless you write a server for them on the same domain.
I did essentially the same thing, but with a Java applet:
http://stephengware.com/proj/javasocketbridge
This must be older, cause it doesn’t work for me in either browser. I have been trying to get this to work for ages on my own. But cannot get the flash to connect once inside a web page. Stand-alone the exe or swf works fine from any machine and connects. But when embedding the flash into a web page, it fails to connect every time. If this has worked in the past PLEASE email me how you got it to work. Thanks
Have You looked at the date of the article?