Sha256: 9ca5f133e503fbab0120c1f26c077e8fd43301c76d2512d89bad1cdafef4bb88

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'lab_bench'

require 'eventmachine'
require 'em-websocket'
require 'sinatra/base'
require 'thin'
require 'yajl'

SOCKETS = []

class LabBenchServer < Sinatra::Base
  set :public, LabBench::ASSETS
  
  get '/' do
    redirect '/index.html'
  end
  
  # lets the babyship ensure that we're up and running
  get '/ping' do
    'Pong!'
  end
  
  # give the babyship a chance to post events, that we just rebroadcast
  post '/test_event' do
    message = Yajl::Encoder.encode(params.merge(:milliseconds => (Time.now.to_f * 1000).to_i))
    SOCKETS.each { |s| s.send message }
    
    # should vend back a UID for this test run or something
    # might also need to accept a UID that the client has already given us
    'Okay'
  end
end

EventMachine.run do
  # HACK - websockets and HTTP on different (adjacent) ports
  EventMachine::WebSocket.start(:host => '0.0.0.0', :port => 9021) do |ws|
    ws.onopen do
      SOCKETS << ws
    end
    
    ws.onclose do
      SOCKETS.delete(ws)
    end

    ws.onerror   { |e| puts "Error: #{e.message}" }
  end
  
  LabBenchServer.run!(:host => '0.0.0.0', :port => 9020)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lab_bench-0.2.0 bin/lab_bench_server