Push Server Technology in Ruby On Rails with Juggernaut
2
For an application that requires interactive communication between the users, chatting is one of the most suitable tools to help you achieve this aspect . A lot of chatting programs are available, alot of chatting sites are available, but if you want to make a browser based chatting through your application, this might seem to be a little bit complicated.
The main problem is that our traditional browsers pull the page from the server using requests and the server replies with a response; this model is not applicable for usage in a browser based chatting application. What is supposed to happen when client X sends the data to client Y ? Client X sends the data to the server then the server pushs this data to client Y. In our traditional model, the server can't send the data to the browser without a request from the client - this gives us limited choices for implementation, as periodically asking the server for new data is not efficent and has a high cost.
So what is the solution? PUSH SERVERS TECHNOLOGY
Push technology, or server push, describes a style of Internet-based communication where the request for a given transaction originates with the publisher or the central server. It is contrasted with pull technology, where the request for the transmission of information originates with the receiver or client. A lot of Push Servers have been introduced and I have looked at most of them. The most exceptional one is the Flash Media Server, but it's not free for more than 10 connected users, and you can simply look at its price to know why it's not feasible that it can be used by startups.
So since I have been working with Ruby On Rails, I searched for a neat Ruby On Rails solution. The result was Juggernaut Push Server Plugin, which seemed like an excellent solution for my work. However, let's take a look at Juggernaut.
Juggernaut is a push server written in Ruby , that can make your application interactively communicate with the server. Juggernaut uses flash objects , javascripts , rails code .
How does Juggernaut work ?
Juggernaut uses a flash object in the browser with a server socket, which makes juggernaut work on almost 90 % of the current browsers as it only requires flash 8.
Juggernaut Consists of three main parts
- In-browser/client side elements,
- A stand alone push server, and
- Rails elements to tie everything together.
So this is a simple chat scenario....
- Browser connects to Rails server, recieves the required javascripts, SWFs files. ( Element 1 )
- The browser creates a flashXML socket with the push server ( used for listening ). ( Element 1 )
- The Client sends the data, using AJAX method, to a controller. ( Element 3 )
- Rails sends the data to the push server using the Juggernaut plugin methods. ( Element 3 )
- Juggernaut push server broadcasts the data to the channels. ( Element 2 )
- Clients receives the new data using the flashXML socket and updates the dom elements with Javascript. ( Element 1)
Juggernaut has different modes of operation; the data can be sent to a certain channel ( no. of users ) or to a specific user.
Advantages of Juggernaut:
- It allows a real time connection with a client - Rails can literally push javascript in real time to the client, after which the javascript is evaluated.
- Using flash sockets allows us to use different ports other than the Rails application port, which helps in not overloading the application server with requests which may lead to the crashing of the application. That's why we need a stand alone application server.
- Push server is written in Ruby using EventMachine. EventMachine has a non-blocking IO, so scales very well.
- It os integrated, as a plugin, into Rails.
- Subscribers can subscribe to multiple channels, and broadcasters can broadcast to multiple channels.
- Broadcasts can be made to channels, or to a specific client.
- There are Connect/Disconnect triggers.
- It has authentication support.
- It uses Flash 8, which installed on more than 95% of computers.
- It supports all the major browsers (uses ExternalInterface): Firefox 1+, IE 6+ and Safari 2+
So how can one use Juggernaut?
This is a very good tutorial about installing and using Juggernaut in your application; it is quite straight forward in Linux.
Hope this was helpful!
Written By:
Moustafa A. Emara ( moustafaemara.wordpress.com )
Comments
Post a Comment
eSpace podcast Prodcast
Archive
Latest Comments
- SpectraMind Commented on Egypt Wins UK's National Outsourcing Association Award
- Rofaida Awad Commented on Go Egypt Go!
- Different Mike Commented on Only idiots change their iPhone root password!
- Mike Commented on Only idiots change their iPhone root password!
- smile Commented on Only idiots change their iPhone root password!

