The Joomla! Community Magazine™

Integrating WebSocket to Joomla!

Written by | Wednesday, 28 December 2011 19:03 | Published in 2012 January
The purpose of this paper is to present WebSocket technology, included in the latest HTML5 specification, which allows much faster communication and dynamic communication server / client.
That is WebSocket?

Wikipedia says:

"WebSocket is a technology providing for bi-directional, full-duplex communications channels, over a single Transmission Control Protocol (TCP) socket. It is designed to be implemented in web browsers and web servers, but it can be used by any client or server application."

To understand the implications of WebSocket, we should first explain how the web works today: Every time you load a site, send a form, click on some link that makes the browser is to send a request to the Web server that is responsible for resolving this petition and show the response. (Polling)

On the other hand we have the connection using WebSocket where the client sends a single petition called 'handshake' where is created a single bidirectional connection directly. (WebSockets)

This opens a new way for developments such as financial systems, medical applications or any application requiring real-time connections.

All very nice... how is used?

Here is where things are separated, on one hand we have the client and the other the server. There are currently several developing WebSocket servers such as:

But taking advantage that Joomla! Platform gives us the possibility to use the library on the command line, we can to think create our own WebSocket server using the library.

To write a WebSocket server developed in PHP and using Joomla! Platform as a structure you need to have special classes and objects using sockets, these objects are not included in the official version of Joomla! Platform, so I created a new library based on work by Andrew Eddie on WebSocket for Joomla! Platform including configuration management and WebSocket server.

These libraries can be downloaded from the fork that I created in my GitHub account: https://github.com/fastslack/joomla-platform/tree/sockets/libraries/joomla/socket

WebSocket server installation

mkdir websocket_example, cd websocket_example
git clone -b sockets git://github.com/fastslack/joomla-platform.git
git clone git://github.com/fastslack/websocket-example.git
cd websocket-example
configuration.dist.php cp configuration.php

After this, edit the configuration.php file and put there data access to MySQL server.

Running the server

Now the only thing left to do is run the server to start the whole process:

$ cd cli
$. /websocket_example
Starting server ...

Testing the server connection WebSocket

Once we have WebSocket server running, we install and configure the com_websockets where the client is connecting to the server. This component will include the javascript files (*. js) required to perform these tasks.

This article does not attempt to create a component for Joomla, for that there are many good tutorials on the Web. So I will offer to download and test the component finished and ready for use.

Conclusions

WebSocket promises to be a good platform for the long-sought 'bidirectional transfer' in the HTTP and HTML that allow the reduction in data transfer and enabling tools to create much faster and dynamic real-time and if we add to this the various features that can implement the Joomla! Platform library the horizon becomes very promising.

Have fun!

Read 20798 times
Tagged under Developers
Matias Aguirre

Matias Aguirre

Matias Aguirre is a young Argentine programmer with extensive experience in open source systems and events involving Free Software in Latin America and the world. A fervent advocate of open source has been used since 1996 free systems using Slackware GNU / Linux as a development platform.

By the year 1999 met the PHP programming language and over time was developing, fixing and improving management systems like Mambo free, Wordpress and Joomla! the latter being among the large community preferences and quality of developed code.

In the absence of solutions in the field of data migration between versions, in January 2008 created the migration tool
called mtwMigrator that migrates data from a Joomla! 1.0 to Joomla! 1.5. This tool was very useful to users and Joomla! and opened the way to the development of jUpgrade with input and support all Joomla! community as well as major developers of Joomla!