Skip to content

Instantly share code, notes, and snippets.

@ucnv
Created November 6, 2009 08:53
Show Gist options
  • Save ucnv/227856 to your computer and use it in GitHub Desktop.
Save ucnv/227856 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Realtime push example using evma_httpserver's send_chunks
# It's taken from http://github.com/tobi/clarity
require 'eventmachine'
require 'evma_httpserver'
class Handler < EventMachine::Connection
include EventMachine::HttpServer
def process_http_request
response = EventMachine::DelegatedHttpResponse.new( self )
response.status = 200
response.headers['Content-Type'] = 'text/html'
response.chunk ' ' * 1024 # magic...
response.chunk '<p>Hi!</p>'
response.send_chunks
@timer = EventMachine.add_periodic_timer(3) do
puts "Ho!"
response.chunk '<p>Hi!</p>'
response.send_chunks
end
end
def unbind
@timer.cancel if @timer
end
end
EventMachine::run do
EventMachine.epoll
EventMachine::start_server('0.0.0.0', 8080, Handler)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment