Skip to content

Instantly share code, notes, and snippets.

@mloughran
Created November 29, 2010 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mloughran/720094 to your computer and use it in GitHub Desktop.
Save mloughran/720094 to your computer and use it in GitHub Desktop.
Example of subclassing WebSocket::Connection
require 'rubygems'
require 'eventmachine'
require 'em-websocket'
class CustomWSConnection < EventMachine::WebSocket::Connection
def trigger_on_message(msg)
send "Pong: #{msg}"
end
def trigger_on_open
send "Hello Client!"
end
def trigger_on_close
puts "WebSocket closed"
end
end
EM.run {
EM.start_server('0.0.0.0', 8080, CustomWSConnection, {:debug => true})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment