Integrating WebSocket to Joomla!

Integrating WebSocket to Joomla!

The purpose of this paper is to present WebSocket technology, included in the latest HTML5 specification, which allows much faster 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.

NOTE: The image was created by WebSocket.org Thanks very much to the authors.

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
cp configuration.dist.php 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 connection to WebSocket server

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!

Newsletter

Quick contact

If you need to contact us below the tracks offer direct contact: