Skip to content

Instantly share code, notes, and snippets.

@unplugandplay
Created April 19, 2019 09:30
Show Gist options
  • Save unplugandplay/985a17ab08c1f38786094311685ff249 to your computer and use it in GitHub Desktop.
Save unplugandplay/985a17ab08c1f38786094311685ff249 to your computer and use it in GitHub Desktop.
simplest ever SSE streaming written in crystal
# glow.cr
# simplest ever SSE streaming
# you can test it with the following bash command
# curl http://127.0.0.1:8888
#
require "http/server"
server = HTTP::Server.new do |context|
context.response.content_type = "text/event-stream"
10.times do |i_times|
context.response.print "retry: 1000
event: message
id: #{i_times}
data: Hello word no #{i_times + 1} !
"
context.response.flush
sleep 1
end
end
p Time.now
address = server.bind_tcp 8888
puts "Listening on http://#{address}"
server.listen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment