-
-
Save unplugandplay/985a17ab08c1f38786094311685ff249 to your computer and use it in GitHub Desktop.
simplest ever SSE streaming written in crystal
This file contains hidden or 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
# 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