Skip to content

Instantly share code, notes, and snippets.

@sdogruyol
Created May 29, 2016 11:57
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 sdogruyol/d886e37de3a15fb64818188459033829 to your computer and use it in GitHub Desktop.
Save sdogruyol/d886e37de3a15fb64818188459033829 to your computer and use it in GitHub Desktop.
require "http/server"
server = HTTP::Server.new "0.0.0.0", 8080 do |context|
context.response.headers["Content-Type"] = "text/event-stream"
stream_channel = Channel(String).new
spawn do
loop do
sleep 0.1
stream_channel.send "Hello World"
end
end
loop do
context.response.puts(stream_channel.receive)
context.response.flush
end
end
puts "Listening on http://0.0.0.0:8080"
server.listen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment