Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd want to implement a Real-time chat for my Rails app but I can't really host the server which handles the sockets. I've tried Faye but it needs a server. I've also heard of pusher but it's limited to 20 users at a time on the chat and I can't really be sure they won't be more.

I've thought of IRC but I think I can't really embed it into a rails app, maybe it needs sockets...

How can I implement a real-time chat without owning a server?

share|improve this question

closed as too broad by gnat, Snowman, GlenH7, amon, MichaelT May 24 '15 at 12:17

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

There's a lot of great solutions, but none that will work without a server to host them on. – Andrew Nov 15 '11 at 1:02
up vote 4 down vote accepted

You can't implement real-time chat without having a server capable of coordinating it in real time. Typical shared host web server setups are not suitable for this sort of thing -- they usually don't have the right sorts of things installed and typically don't have the umph to handle the traffic in any case. So typically you'll need to secure at least your own VPS especially if you care about performance and reliability.

share|improve this answer

If you want to try something new, you can use :

For you, cramp might be useful. I have created a basic demo for a peer to peer chat. It is not for production, but you can find out enough information :

em-wesocket Chat Demo

It is done with em-websocket and

In this demo, I am not using redis but with redis you can achieve more scalability and persistence.

Cramp or nodejs will work for you.

share|improve this answer
Cramp seems very promising for Ruby developers. – garbage collection Oct 15 '12 at 18:03
You'll most likely need a server, but Rails can handle websockets marvelously. Check out this gem to get some real time behavior into your Rails app: – dchacke Feb 13 '15 at 8:54

You can try out PubNub :

PubNub is considered a Web Push Engine able to push (or stream) any textual data in real-time data push to any types of clients across the Internet. PubNub solves all the complexity of pushing data in a scalable, secure, efficient, reliable and portable way. On the client side, APIs are provided so that it is very easy to build Bidirectional Data Push Apps (transforming your existing client or creating a new one from scratch). A powerful HTML5 library makes it possible to push data updates to Mobile Phones, Tablets and Web Pages in real-time data push through a zero-install client.

share|improve this answer

Why are you not able to host it yourself? Is it the cost of hosting?

You could try Socket.IO running on Node.JS, hosted on a free Heroku account. The HTML would remain in your rails app, but the "web socket server" (technically a long-polling server in the case of Heroku) would be running on a free Heroku account.

Other than that, I'm not sure what you are asking. In order to host a website, you need a web host. In order to host a chat server, you need a server to host it on.

share|improve this answer

Web sockets are by far the most efficient way to handle chat functionalities. As a framework, Rails is not very good at handling asynchronous events and therefore establishing a socket connection to a Rails application is almost impossible. There are many solutions that are designed to handle this kind of problem. As Andrew said, Frameworks such as Node.js with Socket.IO would suffice, or, if you want to stick with Ruby, Cramp, async_sinatra, or Goliath framework are all great solutions but it would be super awesome to continue.

If you wanted to use Rails for your application's logic and also have the benefits of some kind of asynchronous event handling with publishing and subscribing you will need to use something like Private Pub Gem which is built on top of Faye and makes it dead simple to publish and subscribe to real-time events in a Rails app.

I have tried to put together a Gmail-like instant message chat application in a rails 4 app. Check out this tutorial. Hope that helps shed some light on the same.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.