Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Created February 5, 2014 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbuehlmann/8818864 to your computer and use it in GitHub Desktop.
Save tbuehlmann/8818864 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'em-websocket'
require 'sinatra/base'
require 'thin'
class App < Sinatra::Base
get '/' do
return "foo"
end
end
EventMachine.next_tick do
EventMachine::WebSocket.start(:host => '0.0.0.0', :port => 8080) do |ws| # <-- Added |ws|
# Websocket code here
ws.onopen {
ws.send "connected!!!!"
}
ws.onmessage { |msg|
puts "got message #{msg}"
}
ws.onclose {
ws.send "WebSocket closed"
}
end
end
App.run!({:port => 3000})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment