Created
November 6, 2009 08:53
-
-
Save ucnv/227856 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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