Skip to content

Instantly share code, notes, and snippets.

@Gowiem
Created March 21, 2013 16:31
Show Gist options
  • Save Gowiem/5214440 to your computer and use it in GitHub Desktop.
Save Gowiem/5214440 to your computer and use it in GitHub Desktop.
Initializing WebSocket Manager
def initialize
puts "--Initializing Message Monitor"
EM.run {
puts "before Faye::Websocket::Client.new()"
ws = Faye::WebSocket::Client.new("wss://somewebsocket.com:/ms/monitor")
puts "After Faye::Websocket::Client.new()"
ws.onopen do |event|
puts "WebSocket Opened!"
ws.send('Hello, world!')
end
ws.onmessage do |event|
puts "WebSocket Message:"
message = JSON.parse(event.date)
puts message
end
ws.onclose do |event|
code = JSON.parse(event.code)
reason = JSON.parse(event.reason)
puts "MessageMonitor onClose:"
puts "Code: #{code}"
puts "Reason: #{reason}"
ws = nil
end
}
puts "Before end of MessageMonitor Initialize"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment