Simple Multiplayer game in Ruby on Rails? Simple Multiplayer game in Ruby on Rails? ajax ajax

Simple Multiplayer game in Ruby on Rails?


What's the simplest thing you can do to solve the user's problem? In this case it is probably "I want to be notified when the person I am playing against makes a move". Real-time isn't a requirement, just that within a second or two, the user is notified.

In which case it would be easiest to keep your Rails app as it is, and use Jquery to 'poll' for new 'moves' every few seconds using JQuery and a plugin such as http://plugins.jquery.com/project/smartupdater

I say this as someone who is currently building an application which uses Websockets in a major way. Whilst it is great in principle, we will be building a Flash version as a fallback for browsers which do not support it.


If you end up using websockets:

Websockets can be implemented with Rails, but not all hosting environments support it. Here are a couple links that might help you get started:

http://m.onkey.org/websockets-made-easy-with-cramp (requires Thin or Rainbows!)

http://www.pusherapp.com/ (if you are using Heroku, this one is a good option)

For the client-side, some javascript plugins have a flash fallback if the browser does not support websockets. Instead of implementing the entire game in flash, you might be better off using such a plugin. (Your server would still require websocket support.) Here is one option (requires jQuery):

https://github.com/ffdead/jquery-graceful-websocket

As you stated, websockets are very new, and as a result will be quite experimental. If all else fails, there are more common AJAX solutions out there. It is possible that for a simple card game, you could just periodically query the server using AJAX requests until the other player has made a move. This would probably increase server load, so I guess it depends on your needs.

Edit:

See also: Juggernaut