Last active
August 29, 2016 05:17
-
-
Save grokify/475c367cb2f35cb85c99e89c65b806dc to your computer and use it in GitHub Desktop.
WebSocket Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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