title: padrino && websockets
body: <p>i'm looking for a way to open and use websockets from within a <a href="http://padrinorb.com" rel="nofollow noreferrer">Padrino</a> application. i know Padrino works with a single thread but i'm looking for a way to open websockets and share variables between its "onopen" "onclose" "onmessage" methods and Padrino controllers.</p>
  
  <p>any idea how it's done ?</p>
  
  <p>links i looked into:</p>
  
  <p><a href="https://stackoverflow.com/questions/2999430/any-success-with-sinatra-working-together-with-eventmachine-websockets">Examples of Eventmachine usage with Padrino and Sinatra</a> (only Sinatra worked for me)
  <a href="https://github.com/igrigorik/em-websocket" rel="nofollow noreferrer">em-websocket on GitHub</a></p>
  
  <p>UPDATE 1:
  this is my main.rb:</p>
  
  <pre><code>    require 'rubygems'      # &lt;-- Added this require
  require 'em-websocket'
  require 'padrino-core'
  require 'thin'
  
  require File.expand_path("../config/boot.rb", __FILE__)
  
  SOCKETS = []
  EventMachine.run do     # &lt;-- Changed EM to EventMachine
  #  class App &lt; Sinatra::Base
  #      get '/' do
  #          SOCKETS.each {|s| s.send "fooooo"}
  #          return "foo"
  #      end
  #  end
  
    EventMachine::WebSocket.start(:host =&gt; '0.0.0.0', :port =&gt; 8080) do |ws| # &lt;-- Added |ws|
        # Websocket code here
        ws.onopen {
            ws.send "connected!!!!"
            SOCKETS &lt;&lt; ws
        }
  
        ws.onmessage { |msg|
            puts "got message #{msg}"
            ws.send "ECHO: #{msg}"
        }
  
        ws.onclose   {
            ws.send "WebSocket closed"
            SOCKETS.delete ws
        }
  
    end
  
    # You could also use Rainbows! instead of Thin.
    # Any EM based Rack handler should do.
    #App.run!({:port =&gt; 3000})    # &lt;-- Changed this line from Thin.start to App.run!
    Thin::Server.start Padrino.application, '0.0.0.0', 3000
  </code></pre>
  
  <p>end</p>
  
  <p>i'm getting this exception:</p>
  
  <pre><code>/home/cstore/.rvm/gems/ruby-1.9.2-p290@runtime/gems/thin-1.2.11/lib/thin/daemonizing.rb:2:in `require': no such file to load -- daemons (LoadError)
      from /home/cstore/.rvm/gems/ruby-1.9.2-p290@runtime/gems/thin-1.2.11/lib/thin/daemonizing.rb:2:in `&lt;top (required)&gt;'
      from /home/cstore/.rvm/gems/ruby-1.9.2-p290@runtime/gems/thin-1.2.11/lib/thin/server.rb:50:in `&lt;class:Server&gt;'
      from /home/cstore/.rvm/gems/ruby-1.9.2-p290@runtime/gems/thin-1.2.11/lib/thin/server.rb:48:in `&lt;module:Thin&gt;'
      from /home/cstore/.rvm/gems/ruby-1.9.2-p290@runtime/gems/thin-1.2.11/lib/thin/server.rb:1:in `&lt;top (required)&gt;'
      from main.rb:39:in `block in &lt;main&gt;'
      from /home/cstore/.rvm/gems/ruby-1.9.2-p290@runtime/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `call'
      from /home/cstore/.rvm/gems/ruby-1.9.2-p290@runtime/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
      from /home/cstore/.rvm/gems/ruby-1.9.2-p290@runtime/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
      from main.rb:9:in `&lt;main&gt;'
  </code></pre>
  
  <p>UPDATE 2:
  Resolved thanks to Nathan !
  I just added 'daemons' to Gemfile and reloaded my application.</p>