Skip to content

Instantly share code, notes, and snippets.

@grokify
Last active August 29, 2016 05:17
Show Gist options
  • Save grokify/475c367cb2f35cb85c99e89c65b806dc to your computer and use it in GitHub Desktop.
Save grokify/475c367cb2f35cb85c99e89c65b806dc to your computer and use it in GitHub Desktop.
WebSocket Notes
require 'faye/websocket'
require 'eventmachine'
i = 0
EM.run {
ws = Faye::WebSocket::Client.new('ws://echo.websocket.org/')
ws.on :open do |event|
p [:open]
ws.send('Hello, world!')
end
ws.on :message do |event|
p [:message, event.data]
if i < 10
i += 1
ws.send(event.data + ' ' + i.to_s)
end
end
ws.on :close do |event|
p [:close, event.code, event.reason]
ws = nil
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment