Bryan
Bryan

Reputation: 3280

Robust TCP server for Ruby?

Could any one recommend a robust TCP server (like Node.js for JavaScript) for Ruby? I understand that there is a TCPServer class available for Ruby but I need something that is more robust because I don't want to have to write code to deal with multiple clients and multi-threads etc. Is there any library/framework for Ruby TCP server that is sort of like Node.js?

Upvotes: 2

Views: 871

Answers (2)

the Tin Man
the Tin Man

Reputation: 160551

Take a look at Sinatra, in particular their "README". It's quite easy to use, handles multiple clients and multi-threads and is easy to set up.

As they show on the front page of their site, put this in a file called "hi.rb":

require 'sinatra'

get '/hi' do
  "Hello World!"
end

Then, at the command-line type:

gem install sinatra
ruby hi.rb

You'll be off and running. If you install Thin using gem install thin, Sinatra will use it as its underlying HTTPd, and you'll gain Event Machine's underpinnings.

Sinatra is the fastest and simplest way to get something on the web in Ruby that I know, and it's quite robust. For normal in-house use it's awesome.

As a next step above Sinatra, look at Padrino. It's built on-top of Sinatra but is a bit more Rails like.

I'll also recommend looking at HAML for generating your HTML content. It's a great tool.

Upvotes: 1

Chris Heald
Chris Heald

Reputation: 62658

It sounds like you're wanting EventMachine or Celluloid. EM is event-driven concurrency, which operates very similarly to node.js. Celluloid is more traditional multithreading.

If you're using MRI, I'd recommend looking at EM first, due to limitations in MRI Ruby's concurrency model. If you're on JRuby, then Celluloid may be the right solution.

Upvotes: 3

Related Questions