Thursday, May 8, 2008

jSocket, javascript with socket connectivity

Inspired by socketjs made by Manfred Weber and XMLSocket made by Andrea Giammarchi, I decided to write my own socket library for javascript. Both have their limitations, socketjs is not Object-Oriented and XMLSocket is only available in a packed version.

Three days later I present to you jSocket. jSocket is a lightweight library that makes it possible to connect live to a listening socket. This allows you to stream data directly to your browser. This does not use AJAX. It's fully Object-Orientated. The the connection is live and instant and communication is possible in both directions. In able to do this it uses a feature of Action Script called XMLSocket (not the same as Andrea Giammarchi's XMLSocket). As many of you will know, Action Script runs in Flash/SWF files. jSocket effectively is a bridge between javascript and Action Script.

I published jSocket on Google Code under the open source MIT License. Remember this is still a work in progress, but it's very stable at this stage. It requires jQuery and Flash Player to run.

On the security front, Flash security does apply. This means however that, with the proper security policy server side, you are able to make cross domain connections.

The only drawback is that Flash expects zero terminated packets and because the sockets were intented for XML data, you can only send wrapped binary data, for instance wrapped in base64 strings. Flash also sends out zero terminated packets.

So check out jSocket on where you can find information, documentation and examples.

1 comment:

Manfred said...

hey looks great... regarding the zero byte issue you could upgrade to flash 9 which has a complete new socket api (also with \n")


Please note that anything I write down here is my opinion and mine alone. Please leave a comment if you feel inclined to do so.