Skip to content

Instantly share code, notes, and snippets.

@arturodz
Created January 11, 2017 05:17
Show Gist options
  • Save arturodz/6171c4cc0492f6f5c480c2273f74ebd6 to your computer and use it in GitHub Desktop.
Save arturodz/6171c4cc0492f6f5c480c2273f74ebd6 to your computer and use it in GitHub Desktop.
EM.run {
ws = Faye::WebSocket::Client.new('wss://ws.localhost.com')
ws.on :open do |event|
puts [:open]
ws.send("Alo!")
end
ws.on :error do| event|
puts "Error: #{event.data}"
end
ws.on :message do |event|
puts [:message, event.data]
if event.data.something = true
# execute code here
end
end
ws.on :close do |event|
puts "Client disconnected with status code: #{event.code} and reason: #{event.reason}"
exit 1
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment