Skip to content

Instantly share code, notes, and snippets.

@charlesvallieres
Created December 13, 2014 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesvallieres/0785c76009440cf5098e to your computer and use it in GitHub Desktop.
Save charlesvallieres/0785c76009440cf5098e to your computer and use it in GitHub Desktop.
require "active_support"
require "active_support/all"
require "faye/websocket"
require "eventmachine"
threads = []
begin
threads = (1..200).map do |i|
Thread.new do
EM.run do
ws = Faye::WebSocket::Client.new('ws://127.0.0.1:8105/websocket')
ws.on :open do |event|
p [:open]
ws.send({ msg: "connect", version: "pre2", support: ["pre2"] }.to_json)
end
ws.on :message do |event|
p [:message, event.data]
end
ws.on :close do |event|
p [:close, event.code, event.reason]
ws = nil
end
end
end
end
threads.each { |t| t.join }
rescue Interrupt => e
threads.each do |t|
Thread.kill(t)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment