Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Ruby equivalent of Node.js' socket.io?

If I wanted to translate my node application that uses socket.io into a Ruby on Rails application what are the options for replacing socket.io? (Essentially looking for a socket server for Ruby)

http://socket.io/

Plan to translate the application below: http://www.tokbox.com/blog/creating-chat-roulette-with-node-js-socket-io-and-opentok/

like image 841
Pinky Avatar asked Aug 09 '13 15:08

Pinky


2 Answers

I'd recommend the Faye Ruby implementation as a solid server-side realtime component. It's not a direct port of socket.io but provides you with the realtime infrastructure and some well define messaging concepts that will help you port most realtime applications.

You can find more options via the realtime web tech guide.

like image 83
leggetter Avatar answered Oct 22 '22 16:10

leggetter


Did you look at the Plezi framework?

You can use it either as a separate framework or to augment Rails/Sinatra by adding websocket functionality.

It runs using the Iodine server and supports native websockets, RESTful routes and HTTP streaming, so it's easy to have a fallback position such as long-pulling, much like socket.io does when web sockets don't work.

It's interesting and easy to develop with and has native support for Redis, so it allows websocket broadcasts between processes and machines... although it's still under development, it's full of potential.

A broadcast/echo WebSocket app can look like this:

require 'plezi'

class Echo

  def index
    "this is an echo server - use websockets to connect. test with: https://www.websocket.org/echo.html"
  end

  def on_message data
    _echo data
    broadcast :_echo, data
  end

  def _echo data
    response << data
  end
end

Plezi.route '/', Echo

You can actually put the code in the irb console and the server will start the moment you exit irb using the exit command.

like image 1
Myst Avatar answered Oct 22 '22 16:10

Myst