Skip to content

Instantly share code, notes, and snippets.

@SergeiStruk
Last active October 28, 2015 18:50
Show Gist options
  • Save SergeiStruk/084fa44482c0a2f27727 to your computer and use it in GitHub Desktop.
Save SergeiStruk/084fa44482c0a2f27727 to your computer and use it in GitHub Desktop.
#config/initializers/websocket_handler.rb
EM.next_tick do
@channel = EM::Channel.new
#Simulate messages.
EM::PeriodicTimer.new(3) do
random_string = rand(100_000).to_s
@channel.push random_string
end
EM::WebSocket.run(host: '0.0.0.0', port: 8080) do |ws|
ws.onmessage do |data|
...
end
ws.onclose do
...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment