Push Server Technology in Ruby On Rails with Juggernaut

July 26, 2008

For an application that requires communication and interactive communication between the users , chatting is one of the most suitable to make you achieve this aspect . A lot of chatting programs are availiable , alot of chatting sites are availiable , 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 pulls the page from the server using requests and the server replies with a response , this model is not applicable to use in a browser based chatting application , as what is supposed to happen when client X send 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 puts to us limited choices to implement this  , as periodically asking the server for new data which is not efficent and highly costing.

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 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 ..  I looked at most of them the most exceptional one , was the   Flash Media Server But its not free for more than 10 connected users , and simply you can look at its price to know why its not feasible to be used by startups 🙂 …

So as working with Ruby On Rails , I searched for a neat Ruby On Rails solution , this was the result …  Juggernaut Push Server Plugin . This was an excellent solution for me… 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

  1. in-browser/client side elements
  2. a stand alone push server and
  3. 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 send 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 receive 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

  • Allows a real time connection with a client – Rails can literally push javascript in real time to the client which is then evaluated.
  • Using flash sockets allows us to use different port other than the rails application port , which helps us not to overload the application server with requests which may lead to crash the application , thats why we need a stand alone application server
  • Push server – written in Ruby using EventMachine. EventMachine has a non-blocking IO so scales very well
  • 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.
  • Connect/Disconnect triggers.
  • Authentication support.
  • Uses Flash 8 – installed on more than 95% of computers.
  • Supports all the major browsers (uses ExternalInterface): Firefox 1+, IE 6+ and Safari 2+

My friends and I made juggernaut plugin to add a secured chatting sessions to juggernaut using RSA or DES encryption algorithms , I’ll write  a blog post about it soon.

So How can I use juggernaut..

This is a very good tutorial about installing and using Juggernaut in your application , it is quite straight forward in linux , but it has some problems in installation with windows and it solved here

Hope this was helpful

2 Responses to “Push Server Technology in Ruby On Rails with Juggernaut”

  1. Srinivas Says:

    Good post, very helpful

  2. islam khalil Says:

    check also ape splution for ajax push.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: