2006-05-26
“Real” Javascript Sockets!
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 please give me some feedback!
36 Comments
-
Sehr. Coole. Sache.
-
under what license is it released?
-
Potentially, could this be used to set up a phishing site that sends out spam whenever a visitor, uhhh, visits? If so, there are some scary ramifications.
-
This “novelty” is nothing new.
As far as I remember, it does not work under IE for Mac.
-
Just what I was looking for. I’m developing a javascript browser based game and I wanted real server push.
-
This works great when connecting to a server on localhost, but when connecting to a server over the internet or even over LAN, I simply can’t get it to work.
If anybody knows how to fix my problem, PLEASE help me. I’ve made an awesome online game with this but no players can connect! E-mail me: kaoskorruption at gmail.com. Thanks.
-
I’d be interested in making it work with the new version of flash. I don’t know much about flash but I’ll learn a bit if its necessary. I’ve started to make a game with this and I need it to work with the new flash!
-
This works with the latest flash version in FireFox. It must only be IE that doesn’t work with the new version.
-
hey sly,
this is funny :) -
For IE7 (and possibly previous versions of that piece of crap), SocketJS must send data between each time it receives. That’s stupid.
-
Hi,
This is a great idea. After some rough start I’ve finaly putted it to work with the server (only sending, not receiving yet).
The problem seems to be that “socketjs” send’s a “” character after each send. The server software doesn’t like that…
The server isn’t sending the “” character back and the “socketjs” doesn’t like that either..
Does any one know if this “real sockets” have to send these annoying “” characters on both ways each send?
I don’t have the “flash” editing software so I can’t really tweak anything… :-(
Thanks to all, nice work.
-
Hi
Somebody could explain like patching UnrealiRCD so that it works with socketjs?
Chris socketjs in java does not finish working to me, you can put to download java compiled pleas.
-
Hi AkonD,
you can download the patched server here:
http://dev.dschini.org/Unreal3.2.zip
After unziping you have to set chmod to some important files.
– Manfred -
Hi
I use another version of unrealircd(unrealircd uDB)
I need single the file that there is to change
thx Manfred
-
Outta curiosity, how does your library compare to Aflax?
(I used that library to build my first javascript socket project, but I’m not sure how it compares. The approach is similar…
… but presumably, yours would be a little better, if a person only wanted socket connections and nothing else.
Thanks a lot for figuring this stuff out — it’s a clever solution which really makes a lot of things possible.
-
Hi,
I just started using javascript for client-server programming and found socketJS is very convenient and powerful.Everything works for me if I put it on the local disk of the browser, like file:///C:/test/index.html. It can send and receive data from a remote server.
But it fails when I have it (html, swf) on a web server, like http://192.168.1.203/test/. In this case, I can get the page right and swf is downloaded to the browser. I have “SocketConnect(’192.168.1.201′,6688)” in the html. But when I click on the “Connect”, it tries to connect to 192.168.1.201:80 instead. The destination port is changed to 80.
Any idea?
Thanks for sharing.
-
After hours of testing and scripting i got this result:
- Got 2 recode the linefeeds in Flash for communication with Pear.Net.Server (PHP)
- If message is to large Flash pumped out his socket-message as multiple Packets.
this blew up the Pear-Server :-(I will be happy 4 all tips to resolve this!
-
Great piece of software, I got 2 questions:
1) what is the license type? GPL, LGPL, BSD, Public Domain?
2) What about Flash v8? I read it is not compatible with Flash v8? That means it is useless because everybody will have Flash v8 in 6 months.
-
For all who are having problems when moving your project from localhost to a host on the web, make sure you add www before the hostname. That might help. Aside from that, pretty smooth working with this. Really good stuff.
-
Actually, you need to use www if the url in the address window uses www, if not you can’t. So I wrote a small script that checks window.location.href and returns the appropriate host to connect to. I even made it return “localhost” for cases when I’m testing offline.
-
function getHostName() {
var url = window.location.href;
var index = url.indexOf(”.com”);
if(index == -1) {
return “localhost”;
}
return url.substring(7, index 4);
} -
at the very end that should be index 4 (index plus 4)
-
var i = textInput.value;
if (i !== “”) {
i = i.replace(/\\/g, “\\\\”);
i = i.replace(/’/g, “'”);
i = i.replace(//g, “>”);
window.document.socket.SetVariable(”data”, i);
window.document.socket.TCallLabel(”/”, “send”);
textInput.value = “”;
} -
Hi
I’m really confused. I can’t get it to work properly. I uploaded this script 1:1 to my web server. But it always says “connection failed”. Local it’s working but not on my webserver. I’d like to connect to your dev.dschini.org:6667.
if you have some hints .. send an email thx
-
Hi Pascal,
That does not work because the socket of the flash-movie within the html page needs to be in the same network domain like the sockets is.
Best Regards
Manfred -
JavaScript sockets and any other OS functionality you might need:
cross platform, cross browser, small footprint and free
-
Hi,
looks interesting. I will have a deeper look at it.
cheers
Manfred -
this wont work for cross domain servers unless you have the crossdomain.xml on the other server google for crossdomain.xml.
-
Is there an equivalent to this that uses Flash 9’s new Socket object? There’s something I’m working on but there’s no way I can easily work around the termination issue of XMLSocket
-
I’m having trouble testing SocketJS in firefox on localhost. I think firefox put some security against this. It still works in Internet Explorer. I’m considering making a version of this using OpenLaszlo or Flex to test further.
-
I got Firefox 3 Beta and it works on localhost like a dream.
-
hey Ken. I had a look at your website an especially the chat system. looks very impressive! wow!
-
There is a good reason why don’t you have sockets in JS/untrusted java applets. Having them is a huge sechole, thats why.
Imagine that the user enters a site then in the next second his/her browser joins a DoS attack without any notice.

