Sha256: d157feeaff9dc889b98c6ce710384bb0414d3cc1cd504b8facde2753afa0cca3

Contents?: true

Size: 663 Bytes

Versions: 9

Compression:

Stored size: 663 Bytes

Contents

require './lib/rack/websocket'

class MyApp < Rack::WebSocket::Application
  def on_open(env)
    puts "client connected"
    EM.add_timer(5) do
      send_data "This message should show-up 5 secs later"
    end

    EM.add_timer(15) do
      send_data "This message should show-up 15 secs later"
    end
  end

  def on_message(env, msg)
    puts "message received: " + msg
    send_data "Message: #{msg}"
  end

  def on_close(env)
    puts "client disconnected"
  end
end

# use Rack::CommonLogger

map '/' do
  run Rack::File.new(File.expand_path(File.dirname(__FILE__)) + '/html')
end

map '/websocket' do
  run MyApp.new # :backend => { :debug => true }
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
websocket-rack-noodles-0.4.3 example/example.ru
websocket-rack-noodles-0.4.2 example/example.ru
websocket-rack-noodles-0.4.1 example/example.ru
websocket-rack-noodles-0.4.0 example/example.ru
websocket-rack-0.4.0 example/example.ru
websocket-rack-0.3.3 example/example.ru
websocket-rack-0.3.2 example/example.ru
websocket-rack-0.3.1 example/example.ru
websocket-rack-0.3.0 example/example.ru